Skip to content

Commit

Permalink
Make PyLinter subclass ArgumentsManager and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Dec 22, 2021
1 parent 3e0bc0a commit a1b5e5c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -192,6 +193,7 @@ class PyLinter(
config.OptionsManagerMixIn,
reporters.ReportsHandlerMixIn,
checkers.BaseTokenChecker,
config._ArgumentsManager,
):
"""lint Python modules using external checkers.
Expand Down Expand Up @@ -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),
Expand Down
23 changes: 23 additions & 0 deletions tests/config/test_argparse_config.py
Original file line number Diff line number Diff line change
@@ -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]"
1 change: 1 addition & 0 deletions tests/test_regr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit a1b5e5c

Please sign in to comment.