summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-14 18:39:58 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-04-15 10:24:45 +0200
commit89bd946db12b228dc17d69bf7b10fb2a63ef4799 (patch)
tree8498d51ff087f9854a30a7a70f281999699fa3e2
parent60476efd8c1ed05915be63ca4ad3c1556626307d (diff)
downloadpylint-git-89bd946db12b228dc17d69bf7b10fb2a63ef4799.tar.gz
Fix option setting in our testsuite
-rw-r--r--pylint/testutils/decorator.py30
-rw-r--r--tests/test_import_graph.py10
-rw-r--r--tests/unittest_reporting.py10
3 files changed, 22 insertions, 28 deletions
diff --git a/pylint/testutils/decorator.py b/pylint/testutils/decorator.py
index 00ddbeec0..fca91abf9 100644
--- a/pylint/testutils/decorator.py
+++ b/pylint/testutils/decorator.py
@@ -2,35 +2,39 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
+from __future__ import annotations
+
import functools
+from collections.abc import Callable
+from typing import TYPE_CHECKING, Any
-from pylint.config.utils import _parse_rich_type_value
from pylint.testutils.checker_test_case import CheckerTestCase
+if TYPE_CHECKING:
+ from pylint.checkers.base_checker import BaseChecker
+
-def set_config(**kwargs):
- """Decorator for setting config values on a checker.
+def set_config(**kwargs: Any) -> Callable:
+ """Decorator for setting an option on the linter.
Passing the args and kwargs back to the test function itself
allows this decorator to be used on parametrized test cases.
"""
- def _wrapper(fun):
+ def _wrapper(fun: Callable) -> Callable:
@functools.wraps(fun)
- def _forward(self, *args, **test_function_kwargs):
+ def _forward(
+ self: BaseChecker | CheckerTestCase, *args: Any, **test_function_kwargs: Any
+ ) -> None:
"""Set option via argparse."""
- # pylint: disable-next=fixme
- # TODO: Optparse: Revisit this decorator after all checkers have switched
- options = []
for key, value in kwargs.items():
- options += [f"--{key.replace('_', '-')}", _parse_rich_type_value(value)]
- self.linter.config = self.linter._arg_parser.parse_known_args(
- options, self.linter.config
- )[0]
+ self.linter.set_option(key, value)
+ # Reopen checker in case, it may be interested in configuration change
if isinstance(self, CheckerTestCase):
- # reopen checker in case, it may be interested in configuration change
self.checker.open()
+ else:
+ self.open()
fun(self, *args, **test_function_kwargs)
diff --git a/tests/test_import_graph.py b/tests/test_import_graph.py
index b28285b84..a05ebbd71 100644
--- a/tests/test_import_graph.py
+++ b/tests/test_import_graph.py
@@ -85,16 +85,12 @@ def remove_files() -> Iterator:
@pytest.mark.usefixtures("remove_files")
def test_checker_dep_graphs(linter: PyLinter) -> None:
- # pylint: disable-next=fixme
- # TODO: Optparse: Fix how these options are set
linter.set_option("persistent", False)
linter.set_option("reports", True)
linter.set_option("enable", "imports")
- linter.config.import_graph = "import.dot"
- linter.config.ext_import_graph = "ext_import.dot"
- linter.config.int_import_graph = "int_import.dot"
- # ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
- linter.set_option("ignore", ("func_unknown_encoding.py",))
+ linter.set_option("import_graph", "import.dot")
+ linter.set_option("ext_import_graph", "ext_import.dot")
+ linter.set_option("int_import_graph", "int_import.dot")
linter.check(["input"])
linter.generate_reports()
assert exists("import.dot")
diff --git a/tests/unittest_reporting.py b/tests/unittest_reporting.py
index 8fdc89775..37dd1f3fa 100644
--- a/tests/unittest_reporting.py
+++ b/tests/unittest_reporting.py
@@ -180,17 +180,11 @@ def test_multi_format_output(tmp_path):
with redirect_stdout(text):
linter = PyLinter()
linter.load_default_plugins()
- # pylint: disable-next=fixme
- # # TODO: Optparse: Fix how we set these options
- linter.config.persistent = False
- linter.config.reports = True
- linter.config.score = True
- linter._load_reporters(formats)
-
linter.set_option("persistent", False)
- # linter.set_option("output-format", formats)
linter.set_option("reports", True)
linter.set_option("score", True)
+ linter.set_option("score", True)
+ linter.set_option("output-format", formats)
assert linter.reporter.linter is linter
with pytest.raises(NotImplementedError):