-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.py
52 lines (38 loc) · 1.5 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import platform
import re
import sys
from distutils.version import LooseVersion
from nose.tools import eq_
from flake8_strict import _process_code
def _test_processing(test_data_path):
with open(test_data_path, 'rt') as f:
code = f.read()
code = code.strip()
expected_errors = set()
for lineno, line in enumerate(code.splitlines()):
include_errors = True
match = re.search(r' # (.*)$', line.strip('\n'))
if match:
for code_or_version in match.group(1).split():
version_match = re.search(r'py(.*):', code_or_version)
if version_match:
include_errors = (
LooseVersion(platform.python_version()) >=
LooseVersion(version_match.group(1))
)
elif include_errors:
expected_errors.add((lineno + 1, code_or_version))
actual_errors = {
(line, error_code.name)
for line, column, error_code in _process_code(code)
}
not_caught = expected_errors - actual_errors
false_negatives = actual_errors - expected_errors
eq_((not_caught, false_negatives), (set(), set()))
def test_processing_py2_py3():
"""Test the library against Python 2/3 compatible syntaxes."""
_test_processing('test_data_py2_py3.py')
if sys.version_info >= (3, 6):
def test_processing_py36():
"""Test the library against Python 3.6+ specific syntaxes."""
_test_processing('test_data_py36.py')