mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Run refactoring test using py.test
refactor.collect_file_tests is fixed; it uses global variable refactoring_test_dir which is not defined when refactor is used as a module.
This commit is contained in:
@@ -2,6 +2,7 @@ from os.path import join, dirname, abspath
|
|||||||
default_base_dir = join(dirname(abspath(__file__)), 'completion')
|
default_base_dir = join(dirname(abspath(__file__)), 'completion')
|
||||||
|
|
||||||
import run
|
import run
|
||||||
|
import refactor
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
@@ -38,11 +39,15 @@ def pytest_generate_tests(metafunc):
|
|||||||
"""
|
"""
|
||||||
:type metafunc: _pytest.python.Metafunc
|
:type metafunc: _pytest.python.Metafunc
|
||||||
"""
|
"""
|
||||||
if 'case' in metafunc.fixturenames:
|
|
||||||
base_dir = metafunc.config.option.base_dir
|
base_dir = metafunc.config.option.base_dir
|
||||||
test_files = dict(map(parse_test_files_option,
|
test_files = dict(map(parse_test_files_option,
|
||||||
metafunc.config.option.test_files))
|
metafunc.config.option.test_files))
|
||||||
|
if 'case' in metafunc.fixturenames:
|
||||||
thirdparty = metafunc.config.option.thirdparty
|
thirdparty = metafunc.config.option.thirdparty
|
||||||
metafunc.parametrize(
|
metafunc.parametrize(
|
||||||
'case',
|
'case',
|
||||||
run.collect_dir_tests(base_dir, test_files, thirdparty))
|
run.collect_dir_tests(base_dir, test_files, thirdparty))
|
||||||
|
if 'refactor_case' in metafunc.fixturenames:
|
||||||
|
metafunc.parametrize(
|
||||||
|
'refactor_case',
|
||||||
|
refactor.collect_dir_tests(base_dir, test_files))
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class RefactoringCase(object):
|
|||||||
self.name, self.line_nr - 1)
|
self.name, self.line_nr - 1)
|
||||||
|
|
||||||
|
|
||||||
def collect_file_tests(source, f_name, lines_to_execute):
|
def collect_file_tests(source, path, lines_to_execute):
|
||||||
r = r'^# --- ?([^\n]*)\n((?:(?!\n# \+\+\+).)*)' \
|
r = r'^# --- ?([^\n]*)\n((?:(?!\n# \+\+\+).)*)' \
|
||||||
r'\n# \+\+\+((?:(?!\n# ---).)*)'
|
r'\n# \+\+\+((?:(?!\n# ---).)*)'
|
||||||
for match in re.finditer(r, source, re.DOTALL | re.MULTILINE):
|
for match in re.finditer(r, source, re.DOTALL | re.MULTILINE):
|
||||||
@@ -86,7 +86,6 @@ def collect_file_tests(source, f_name, lines_to_execute):
|
|||||||
if lines_to_execute and line_nr - 1 not in lines_to_execute:
|
if lines_to_execute and line_nr - 1 not in lines_to_execute:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
path = os.path.join(os.path.abspath(refactoring_test_dir), f_name)
|
|
||||||
yield RefactoringCase(name, source, line_nr, index, path,
|
yield RefactoringCase(name, source, line_nr, index, path,
|
||||||
new_name, start_line_test, second)
|
new_name, start_line_test, second)
|
||||||
|
|
||||||
@@ -96,10 +95,10 @@ def collect_dir_tests(base_dir, test_files):
|
|||||||
files_to_execute = [a for a in test_files.items() if a[0] in f_name]
|
files_to_execute = [a for a in test_files.items() if a[0] in f_name]
|
||||||
lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, [])
|
lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, [])
|
||||||
if f_name.endswith(".py") and (not test_files or files_to_execute):
|
if f_name.endswith(".py") and (not test_files or files_to_execute):
|
||||||
path = os.path.join(refactoring_test_dir, f_name)
|
path = os.path.join(base_dir, f_name)
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
source = f.read()
|
source = f.read()
|
||||||
for case in collect_file_tests(source, f_name, lines_to_execute):
|
for case in collect_file_tests(source, path, lines_to_execute):
|
||||||
yield case
|
yield case
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,3 +101,14 @@ def test_integration(case, monkeypatch, pytestconfig):
|
|||||||
TEST_USAGES: run_related_name_test,
|
TEST_USAGES: run_related_name_test,
|
||||||
}
|
}
|
||||||
testers[case.test_type](case)
|
testers[case.test_type](case)
|
||||||
|
|
||||||
|
|
||||||
|
def test_refactor(refactor_case):
|
||||||
|
"""
|
||||||
|
Run refactoring test case.
|
||||||
|
|
||||||
|
:type refactor_case: :class:`.refactor.RefactoringCase`
|
||||||
|
"""
|
||||||
|
refactor_case.run()
|
||||||
|
result, desired = refactor_case.result, refactor_case.desired
|
||||||
|
assert result == desired, "Refactoring test %r fails" % refactor_case
|
||||||
|
|||||||
Reference in New Issue
Block a user