diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-03-24 10:05:19 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-03-28 21:48:17 +0200 |
commit | bb069b8b2841f190124248f19b11a4258dab4c4f (patch) | |
tree | f42a32bfc6db05a06a27810374eae36203b98841 /tests/testutils | |
parent | 2f463663b9b30c5cb1e302e80ea541eded359d96 (diff) | |
download | pylint-git-bb069b8b2841f190124248f19b11a4258dab4c4f.tar.gz |
[refactor] Separate assertion from setup in functional test's test
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/test_lint_module_output_update.py | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/tests/testutils/test_lint_module_output_update.py b/tests/testutils/test_lint_module_output_update.py index 22da7b0f7..4874c9713 100644 --- a/tests/testutils/test_lint_module_output_update.py +++ b/tests/testutils/test_lint_module_output_update.py @@ -90,10 +90,10 @@ def test_lint_module_output_update_remove_useless_txt( ) @pytest.mark.parametrize("directory_path", DIRECTORIES, ids=DIRECTORIES_NAMES) def test_update_of_functional_output(directory_path: Path, tmp_path: Path) -> None: - """Functional test for the functional tests helper.""" + """Functional test for the functional tests' helper.""" - def _check_expected_output(ftf: FunctionalTestFile) -> None: - new_output_path = ftf.expected_output + def _check_expected_output(_ftf: FunctionalTestFile) -> None: + new_output_path = _ftf.expected_output assert Path( new_output_path ).exists(), "The expected output file does not exists" @@ -103,43 +103,54 @@ def test_update_of_functional_output(directory_path: Path, tmp_path: Path) -> No new_output == "exec-used:7:0:7:14::Use of exec:UNDEFINED\n" ), f"The content was wrongly updated in {new_output_path}" - new_path = tmp_path / directory_path.name - shutil.copytree(directory_path, new_path) - for filename in new_path.iterdir(): - if filename.suffix != ".py": - continue - new_path_str = str(new_path) - ftf = FunctionalTestFile(directory=new_path_str, filename=filename.name) - # Standard functional test helper - lint_module = LintModuleTest(ftf) - # Functional test helper that automatically update the output - lint_module_output_update = LintModuleOutputUpdate(ftf) + def _assert_behavior_is_correct( + _ftf: FunctionalTestFile, + _lint_module: LintModuleTest, + _lint_module_output_update: LintModuleOutputUpdate, + _new_path: Path, + ) -> None: + new_path_str = str(_new_path) if "wrong_test" in new_path_str: expected = r'Wrong message\(s\) raised for "exec_used.py"' with pytest.raises(AssertionError, match=expected): - lint_module.runTest() + _lint_module.runTest() # When the tests are wrong we do not update the output at all # and the test should fail with pytest.raises(AssertionError, match=expected): - lint_module_output_update.runTest() + _lint_module_output_update.runTest() elif "ok_test" in new_path_str: if any(f"{x}_output" in new_path_str for x in ("wrong", "no", "broken")): with pytest.raises( AssertionError, match='Wrong output for "exec_used.txt"' ): - lint_module.runTest() + _lint_module.runTest() elif "ok_output" in new_path_str: - lint_module.runTest() - _check_expected_output(ftf) + _lint_module.runTest() + _check_expected_output(_ftf) else: raise AssertionError(f"Unhandled test case: {new_path_str}") # When the tests are ok we update the output whatever it's state # was originally - lint_module_output_update.runTest() - _check_expected_output(ftf) + _lint_module_output_update.runTest() + _check_expected_output(_ftf) else: raise AssertionError( f"Do not pollute '{FIXTURE_DIRECTORY}' with unrelated " f"or badly named test files." ) + + new_path = tmp_path / directory_path.name + shutil.copytree(directory_path, new_path) + for filename in new_path.iterdir(): + if filename.suffix != ".py": + continue + ftf = FunctionalTestFile(directory=str(new_path), filename=filename.name) + # Standard functional test helper + lint_module = LintModuleTest(ftf) + # Functional test helper that automatically update the output + lint_module_output_update = LintModuleOutputUpdate(ftf) + + _assert_behavior_is_correct( + ftf, lint_module, lint_module_output_update, new_path + ) |