mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 21:54:54 +08:00
Make it possible to use certain python versions according to the file name of a normalizer issue file.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
@@ -36,12 +37,12 @@ def pytest_addoption(parser):
|
|||||||
|
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
if 'normalizer_issue_file' in metafunc.fixturenames:
|
if 'normalizer_issue_case' in metafunc.fixturenames:
|
||||||
base_dir = os.path.join(os.path.dirname(__file__), 'test', 'normalizer_issue_files')
|
base_dir = os.path.join(os.path.dirname(__file__), 'test', 'normalizer_issue_files')
|
||||||
|
|
||||||
cases = list(colllect_normalizer_tests(base_dir))
|
cases = list(colllect_normalizer_tests(base_dir))
|
||||||
metafunc.parametrize(
|
metafunc.parametrize(
|
||||||
'normalizer_issue_file',
|
'normalizer_issue_case',
|
||||||
cases,
|
cases,
|
||||||
ids=[c.name for c in cases]
|
ids=[c.name for c in cases]
|
||||||
)
|
)
|
||||||
@@ -55,6 +56,8 @@ class NormalizerIssueCase(object):
|
|||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.name = os.path.basename(path)
|
self.name = os.path.basename(path)
|
||||||
|
match = re.search(r'python([\d.]+)\.py', self.name)
|
||||||
|
self.python_version = match and match.group(1)
|
||||||
|
|
||||||
|
|
||||||
def colllect_normalizer_tests(base_dir):
|
def colllect_normalizer_tests(base_dir):
|
||||||
|
|||||||
@@ -47,18 +47,19 @@ def collect_errors(code):
|
|||||||
yield WantedIssue(code[1:], l, column)
|
yield WantedIssue(code[1:], l, column)
|
||||||
|
|
||||||
|
|
||||||
def test_normalizer_issue(normalizer_issue_file):
|
def test_normalizer_issue(normalizer_issue_case):
|
||||||
def sort(issues):
|
def sort(issues):
|
||||||
issues = sorted(issues, key=lambda i: (i.start_pos, i.code))
|
issues = sorted(issues, key=lambda i: (i.start_pos, i.code))
|
||||||
return ["(%s, %s): %s" % (i.start_pos[0], i.start_pos[1], i.code)
|
return ["(%s, %s): %s" % (i.start_pos[0], i.start_pos[1], i.code)
|
||||||
for i in issues]
|
for i in issues]
|
||||||
|
|
||||||
with open(normalizer_issue_file.path, 'rb') as f:
|
with open(normalizer_issue_case.path, 'rb') as f:
|
||||||
code = source_to_unicode(f.read())
|
code = source_to_unicode(f.read())
|
||||||
|
|
||||||
desired = sort(collect_errors(code))
|
desired = sort(collect_errors(code))
|
||||||
|
|
||||||
module = parso.parse(code)
|
grammar = parso.load_grammar(version=normalizer_issue_case.python_version)
|
||||||
|
module = grammar.parse(code)
|
||||||
issues = module._get_normalizer_issues()
|
issues = module._get_normalizer_issues()
|
||||||
actual = sort(issues)
|
actual = sort(issues)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user