From 56b106117fac04dbfb8db3d218cca8a81edff273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Tue, 7 Sep 2021 11:50:07 +0200 Subject: [PATCH] Change tests for ``filepath`` changes --- tests/checkers/unittest_variables.py | 2 +- tests/extensions/test_broad_try_clause.py | 3 ++- tests/extensions/test_comparetozero.py | 3 ++- tests/lint/test_utils.py | 6 +++--- tests/lint/unittest_lint.py | 10 ++++----- tests/test_check_parallel.py | 12 +++++++---- tests/test_import_graph.py | 2 +- tests/test_regr.py | 26 +++++++++++------------ 8 files changed, 35 insertions(+), 29 deletions(-) diff --git a/tests/checkers/unittest_variables.py b/tests/checkers/unittest_variables.py index 7ab79bf6f49..62a9ca3d0e6 100644 --- a/tests/checkers/unittest_variables.py +++ b/tests/checkers/unittest_variables.py @@ -368,7 +368,7 @@ def test_package_all() -> None: sys.path.insert(0, REGR_DATA_DIR) try: - linter.check(os.path.join(REGR_DATA_DIR, "package_all")) + linter.check([os.path.join(REGR_DATA_DIR, "package_all")]) got = linter.reporter.finalize().strip() assert got == "E: 3: Undefined variable name 'missing' in __all__" finally: diff --git a/tests/extensions/test_broad_try_clause.py b/tests/extensions/test_broad_try_clause.py index 21c79fed06a..a41a7ab3dc7 100644 --- a/tests/extensions/test_broad_try_clause.py +++ b/tests/extensions/test_broad_try_clause.py @@ -13,6 +13,7 @@ """Tests for the pylint checker in :mod:`pylint.extensions.broad_try_clause`""" import unittest from os import path as osp +from typing import Optional from pylint import checkers from pylint.extensions.broad_try_clause import BroadTryClauseChecker @@ -21,7 +22,7 @@ class BroadTryClauseTestReporter(BaseReporter): - def on_set_current_module(self, module: str, filepath: str) -> None: + def on_set_current_module(self, module: str, filepath: Optional[str]) -> None: self.messages = [] def _display(self, layout): diff --git a/tests/extensions/test_comparetozero.py b/tests/extensions/test_comparetozero.py index 167a615efc3..c90c211834b 100644 --- a/tests/extensions/test_comparetozero.py +++ b/tests/extensions/test_comparetozero.py @@ -14,6 +14,7 @@ import os import unittest +from typing import Optional from pylint import checkers from pylint.extensions.comparetozero import CompareToZeroChecker @@ -22,7 +23,7 @@ class CompareToZeroTestReporter(BaseReporter): - def on_set_current_module(self, module: str, filepath: str) -> None: + def on_set_current_module(self, module: str, filepath: Optional[str]) -> None: self.messages = [] def _display(self, layout): diff --git a/tests/lint/test_utils.py b/tests/lint/test_utils.py index 80e7287f0b2..f7294f353cd 100644 --- a/tests/lint/test_utils.py +++ b/tests/lint/test_utils.py @@ -1,4 +1,4 @@ -from pathlib import PosixPath +from pathlib import Path, PosixPath from pylint.lint.utils import get_fatal_error_message, prepare_crash_report @@ -13,7 +13,7 @@ def test_prepare_crash_report(tmp_path: PosixPath) -> None: raise Exception(exception_content) except Exception as ex: # pylint: disable=broad-except template_path = prepare_crash_report( - ex, python_file, tmp_path / "pylint-crash-%Y.txt" + ex, str(python_file), str(tmp_path / "pylint-crash-%Y.txt") ) assert str(tmp_path) in str(template_path) with open(template_path, encoding="utf8") as f: @@ -27,7 +27,7 @@ def test_prepare_crash_report(tmp_path: PosixPath) -> None: def test_get_fatal_error_message() -> None: python_path = "mypath.py" crash_path = "crash.txt" - msg = get_fatal_error_message(python_path, crash_path) + msg = get_fatal_error_message(python_path, Path(crash_path)) assert python_path in msg assert crash_path in msg assert "open an issue" in msg diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 18656ad740a..ef004a08a82 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -269,7 +269,7 @@ def visit_class(self, _): linter.open() out = StringIO() linter.set_reporter(text.TextReporter(out)) - linter.check("abc") + linter.check(["abc"]) def test_enable_message(init_linter: PyLinter) -> None: @@ -573,7 +573,7 @@ def test_init_hooks_called_before_load_plugins() -> None: def test_analyze_explicit_script(linter: PyLinter) -> None: linter.set_reporter(testutils.GenericTestReporter()) - linter.check(os.path.join(DATA_DIR, "ascript")) + linter.check([os.path.join(DATA_DIR, "ascript")]) assert ["C: 2: Line too long (175/100)"] == linter.reporter.messages @@ -826,15 +826,15 @@ def test_filename_with__init__(init_linter: PyLinter) -> None: def test_by_module_statement_value(init_linter: PyLinter) -> None: """Test "statement" for each module analized of computed correctly.""" linter = init_linter - linter.check(os.path.join(os.path.dirname(__file__), "data")) + linter.check([os.path.join(os.path.dirname(__file__), "data")]) for module, module_stats in linter.stats["by_module"].items(): linter2 = init_linter if module == "data": - linter2.check(os.path.join(os.path.dirname(__file__), "data/__init__.py")) + linter2.check([os.path.join(os.path.dirname(__file__), "data/__init__.py")]) else: - linter2.check(os.path.join(os.path.dirname(__file__), module)) + linter2.check([os.path.join(os.path.dirname(__file__), module)]) # Check that the by_module "statement" is equal to the global "statement" # computed for that module diff --git a/tests/test_check_parallel.py b/tests/test_check_parallel.py index f87f818450a..ef12604ce92 100644 --- a/tests/test_check_parallel.py +++ b/tests/test_check_parallel.py @@ -177,7 +177,7 @@ def test_worker_initialize(self) -> None: def test_worker_check_single_file_uninitialised(self) -> None: pylint.lint.parallel._worker_linter = None with pytest.raises( # Objects that do not match the linter interface will fail - AttributeError, match="'NoneType' object has no attribute 'open'" + Exception, match="Worker linter not yet initialised" ): worker_check_single_file(_gen_file_data()) @@ -289,7 +289,9 @@ def test_sequential_checkers_work(self) -> None: # Invoke the lint process in a multiprocess way, although we only specify one # job. - check_parallel(linter, jobs=1, files=single_file_container, arguments=None) + check_parallel( + linter, jobs=1, files=iter(single_file_container), arguments=None + ) assert len(linter.get_checkers()) == 2, ( "We should only have the 'master' and 'sequential-checker' " "checkers registered" @@ -318,7 +320,7 @@ def test_sequential_checkers_work(self) -> None: # now run the regular mode of checking files and check that, in this proc, we # collect the right data - filepath = single_file_container[0][1] # get the filepath element + filepath = [single_file_container[0][1]] # get the filepath element linter.check(filepath) assert { "by_module": { @@ -356,7 +358,9 @@ def test_invoke_single_job(self) -> None: # Invoke the lint process in a multiprocess way, although we only specify one # job. - check_parallel(linter, jobs=1, files=single_file_container, arguments=None) + check_parallel( + linter, jobs=1, files=iter(single_file_container), arguments=None + ) assert { "by_module": { diff --git a/tests/test_import_graph.py b/tests/test_import_graph.py index 8029707189f..42e3baf56b4 100644 --- a/tests/test_import_graph.py +++ b/tests/test_import_graph.py @@ -106,7 +106,7 @@ def test_checker_dep_graphs(linter: PyLinter) -> None: linter.global_set_option("int-import-graph", "int_import.dot") # ignore this file causing spurious MemoryError w/ some python version (>=2.3?) linter.global_set_option("ignore", ("func_unknown_encoding.py",)) - linter.check("input") + linter.check(["input"]) linter.generate_reports() assert exists("import.dot") assert exists("ext_import.dot") diff --git a/tests/test_regr.py b/tests/test_regr.py index 793a1961298..ac9e5c5805d 100644 --- a/tests/test_regr.py +++ b/tests/test_regr.py @@ -61,15 +61,15 @@ def Equals(expected): @pytest.mark.parametrize( "file_name, check", [ - ("package.__init__", Equals("")), - ("precedence_test", Equals("")), - ("import_package_subpackage_module", Equals("")), - ("pylint.checkers.__init__", lambda x: "__path__" not in x), - (join(REGR_DATA, "classdoc_usage.py"), Equals("")), - (join(REGR_DATA, "module_global.py"), Equals("")), - (join(REGR_DATA, "decimal_inference.py"), Equals("")), - (join(REGR_DATA, "absimp", "string.py"), Equals("")), - (join(REGR_DATA, "bad_package"), lambda x: "Unused import missing" in x), + (["package.__init__"], Equals("")), + (["precedence_test"], Equals("")), + (["import_package_subpackage_module"], Equals("")), + (["pylint.checkers.__init__"], lambda x: "__path__" not in x), + ([join(REGR_DATA, "classdoc_usage.py")], Equals("")), + ([join(REGR_DATA, "module_global.py")], Equals("")), + ([join(REGR_DATA, "decimal_inference.py")], Equals("")), + ([join(REGR_DATA, "absimp", "string.py")], Equals("")), + ([join(REGR_DATA, "bad_package")], lambda x: "Unused import missing" in x), ], ) def test_package(finalize_linter, file_name, check): @@ -94,7 +94,7 @@ def test_crash(finalize_linter, file_name): "fname", [x for x in os.listdir(REGR_DATA) if x.endswith("_crash.py")] ) def test_descriptor_crash(fname: str, finalize_linter: PyLinter) -> None: - finalize_linter.check(join(REGR_DATA, fname)) + finalize_linter.check([join(REGR_DATA, fname)]) finalize_linter.reporter.finalize().strip() @@ -109,13 +109,13 @@ def modify_path() -> Iterator: @pytest.mark.usefixtures("modify_path") def test_check_package___init__(finalize_linter: PyLinter) -> None: - filename = "package.__init__" + filename = ["package.__init__"] finalize_linter.check(filename) checked = list(finalize_linter.stats["by_module"].keys()) - assert checked == [filename] + assert checked == filename os.chdir(join(REGR_DATA, "package")) - finalize_linter.check("__init__") + finalize_linter.check(["__init__"]) checked = list(finalize_linter.stats["by_module"].keys()) assert checked == ["__init__"]