diff --git a/test/conftest.py b/test/conftest.py index 3ed26cfb..ae57594f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -2,6 +2,7 @@ from os.path import join, dirname, abspath default_base_dir = join(dirname(abspath(__file__)), 'completion') import run +import refactor def pytest_addoption(parser): @@ -38,11 +39,15 @@ def pytest_generate_tests(metafunc): """ :type metafunc: _pytest.python.Metafunc """ + base_dir = metafunc.config.option.base_dir + test_files = dict(map(parse_test_files_option, + metafunc.config.option.test_files)) if 'case' in metafunc.fixturenames: - base_dir = metafunc.config.option.base_dir - test_files = dict(map(parse_test_files_option, - metafunc.config.option.test_files)) thirdparty = metafunc.config.option.thirdparty metafunc.parametrize( 'case', 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)) diff --git a/test/refactor.py b/test/refactor.py index e4cc7c08..83bcaa98 100755 --- a/test/refactor.py +++ b/test/refactor.py @@ -64,7 +64,7 @@ class RefactoringCase(object): 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'\n# \+\+\+((?:(?!\n# ---).)*)' 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: continue - path = os.path.join(os.path.abspath(refactoring_test_dir), f_name) yield RefactoringCase(name, source, line_nr, index, path, 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] 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): - path = os.path.join(refactoring_test_dir, f_name) + path = os.path.join(base_dir, f_name) with open(path) as f: 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 diff --git a/test/test_integration.py b/test/test_integration.py index 69ef90e1..c481fb5c 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -101,3 +101,14 @@ def test_integration(case, monkeypatch, pytestconfig): TEST_USAGES: run_related_name_test, } 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