From a1b5e5ce7b70956adf6a7539e86a02ee84d4c8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Wed, 22 Dec 2021 09:55:54 +0100 Subject: [PATCH] Make ``PyLinter`` subclass ``ArgumentsManager`` and add tests --- pylint/lint/pylinter.py | 3 +++ tests/config/test_argparse_config.py | 23 +++++++++++++++++++++++ tests/test_regr.py | 1 + 3 files changed, 27 insertions(+) create mode 100644 tests/config/test_argparse_config.py diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 023455f68e4..472ed893169 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -1,6 +1,7 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE +import argparse import collections import contextlib import functools @@ -192,6 +193,7 @@ class PyLinter( config.OptionsManagerMixIn, reporters.ReportsHandlerMixIn, checkers.BaseTokenChecker, + config._ArgumentsManager, ): """lint Python modules using external checkers. @@ -600,6 +602,7 @@ def __init__( self._by_id_managed_msgs: List[ManagedMessage] = [] reporters.ReportsHandlerMixIn.__init__(self) + config._ArgumentsManager.__init__(self, argparse.Namespace()) super().__init__( usage=__doc__, config_file=pylintrc or next(config.find_default_config_files(), None), diff --git a/tests/config/test_argparse_config.py b/tests/config/test_argparse_config.py new file mode 100644 index 00000000000..a44eb7ff349 --- /dev/null +++ b/tests/config/test_argparse_config.py @@ -0,0 +1,23 @@ +"""Test for the (new) implementation of option parsing with argparse""" + +import argparse + +from pylint import config +from pylint.lint import PyLinter + + +class TestArgumentsManager: + """Tests for the ArgumentsManager class""" + + @staticmethod + def test_initialize_arguments_manager_class(linter: PyLinter) -> None: + """Tests that ArgumentsManager is correctly initialized on a PyLinter class""" + assert isinstance(linter, config._ArgumentsManager) + assert isinstance(linter.namespace, argparse.Namespace) + + @staticmethod + def test_help_message(linter: PyLinter) -> None: + """Test the help_message attribute of the ArgumentsManager class""" + assert isinstance(linter.help_message, str) + lines = linter.help_message.splitlines() + assert lines[0] == "usage: pylint [-h]" diff --git a/tests/test_regr.py b/tests/test_regr.py index 99b60027550..fc377af2c51 100644 --- a/tests/test_regr.py +++ b/tests/test_regr.py @@ -145,6 +145,7 @@ def test_pylint_config_attr() -> None: "BaseTokenChecker", "BaseChecker", "OptionsProviderMixIn", + "_ArgumentsManager", ] assert [c.name for c in pylinter.ancestors()] == expect assert list(astroid.Instance(pylinter).getattr("config"))