diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-11 08:13:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-11 08:13:43 +0200 |
commit | c6022aaea149395dee574a2b147bb6cb12e051e0 (patch) | |
tree | b4b279012002ad17fa14b4495032169f287afee8 /pylint/testutils | |
parent | db911fdb0ef2ddf51864712a40d6fac40cd4f86e (diff) | |
download | pylint-git-c6022aaea149395dee574a2b147bb6cb12e051e0.tar.gz |
Use the standard config parser instead a new one in functional tests (#6572)
Diffstat (limited to 'pylint/testutils')
-rw-r--r-- | pylint/testutils/functional/test_file.py | 1 | ||||
-rw-r--r-- | pylint/testutils/lint_module_test.py | 54 |
2 files changed, 43 insertions, 12 deletions
diff --git a/pylint/testutils/functional/test_file.py b/pylint/testutils/functional/test_file.py index 4fb0f9573..cfa2b3f1d 100644 --- a/pylint/testutils/functional/test_file.py +++ b/pylint/testutils/functional/test_file.py @@ -62,6 +62,7 @@ class FunctionalTestFile: def __init__(self, directory: str, filename: str) -> None: self._directory = directory self.base = filename.replace(".py", "") + # TODO: 2.15: Deprecate FunctionalTestFile.options and related code self.options: TestFileOptions = { "min_pyver": (2, 5), "max_pyver": (4, 0), diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index d6e829b54..a3801f006 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -58,12 +58,6 @@ class LintModuleTest: pass self._test_file = test_file - self._check_end_position = ( - sys.version_info >= self._test_file.options["min_pyver_end_position"] - ) - # TODO: PY3.9: PyPy supports end_lineno from 3.9 and above - if self._check_end_position and IS_PYPY: - self._check_end_position = sys.version_info >= (3, 9) # pragma: no cover try: args = [test_file.source] except NoFileError: @@ -77,9 +71,45 @@ class LintModuleTest: messages_to_enable.add("fatal") messages_to_enable.add("syntax-error") args.extend(["--disable=all", f"--enable={','.join(messages_to_enable)}"]) + + # Add testoptions + self._linter._arg_parser.add_argument( + "--min_pyver", type=parse_python_version, default=(2, 5) + ) + self._linter._arg_parser.add_argument( + "--max_pyver", type=parse_python_version, default=(4, 0) + ) + self._linter._arg_parser.add_argument( + "--min_pyver_end_position", type=parse_python_version, default=(3, 8) + ) + self._linter._arg_parser.add_argument( + "--requires", type=lambda s: [i.strip() for i in s.split(",")], default=[] + ) + self._linter._arg_parser.add_argument( + "--except_implementations", + type=lambda s: [i.strip() for i in s.split(",")], + default=[], + ) + self._linter._arg_parser.add_argument( + "--exclude_platforms", + type=lambda s: [i.strip() for i in s.split(",")], + default=[], + ) + self._linter._arg_parser.add_argument( + "--exclude_from_minimal_messages_config", default=False + ) + _config_initialization( self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter ) + + self._check_end_position = ( + sys.version_info >= self._linter.config.min_pyver_end_position + ) + # TODO: PY3.9: PyPy supports end_lineno from 3.9 and above + if self._check_end_position and IS_PYPY: + self._check_end_position = sys.version_info >= (3, 9) # pragma: no cover + self._config = config def setUp(self) -> None: @@ -88,26 +118,26 @@ class LintModuleTest: f"Test cannot run with Python {sys.version.split(' ', maxsplit=1)[0]}." ) missing = [] - for requirement in self._test_file.options["requires"]: + for requirement in self._linter.config.requires: try: __import__(requirement) except ImportError: missing.append(requirement) if missing: pytest.skip(f"Requires {','.join(missing)} to be present.") - except_implementations = self._test_file.options["except_implementations"] + except_implementations = self._linter.config.except_implementations if except_implementations: if platform.python_implementation() in except_implementations: msg = "Test cannot run with Python implementation %r" pytest.skip(msg % platform.python_implementation()) - excluded_platforms = self._test_file.options["exclude_platforms"] + excluded_platforms = self._linter.config.exclude_platforms if excluded_platforms: if sys.platform.lower() in excluded_platforms: pytest.skip(f"Test cannot run on platform {sys.platform!r}") if ( self._config and self._config.getoption("minimal_messages_config") - and self._test_file.options["exclude_from_minimal_messages_config"] + and self._linter.config.exclude_from_minimal_messages_config ): pytest.skip("Test excluded from --minimal-messages-config") @@ -116,8 +146,8 @@ class LintModuleTest: def _should_be_skipped_due_to_version(self) -> bool: return ( - sys.version_info < self._test_file.options["min_pyver"] - or sys.version_info > self._test_file.options["max_pyver"] + sys.version_info < self._linter.config.min_pyver + or sys.version_info > self._linter.config.max_pyver ) def __str__(self) -> str: |