From b9b957a5508f89afda2eb8073538ceeb27a060ef 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:59:12 +0100 Subject: [PATCH] Set ``future_option_parsing=True`` for logging and add tests --- pylint/checkers/logging.py | 3 +++ tests/config/test_argparse_config.py | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py index 242c5e800da..f403fcafa0c 100644 --- a/pylint/checkers/logging.py +++ b/pylint/checkers/logging.py @@ -163,6 +163,9 @@ class LoggingChecker(checkers.BaseChecker): ), ) + def __init__(self, linter=None): + super().__init__(linter=linter, future_option_parsing=True) + def visit_module(self, _: nodes.Module) -> None: """Clears any state left in this checker from last module checked.""" # The code being checked can just as easily "import logging as foo", diff --git a/tests/config/test_argparse_config.py b/tests/config/test_argparse_config.py index a44eb7ff349..4be473e7b24 100644 --- a/tests/config/test_argparse_config.py +++ b/tests/config/test_argparse_config.py @@ -1,9 +1,13 @@ """Test for the (new) implementation of option parsing with argparse""" import argparse +from os.path import abspath, dirname, join from pylint import config -from pylint.lint import PyLinter +from pylint.lint import PyLinter, Run + +HERE = abspath(dirname(__file__)) +REGRTEST_DATA_DIR = join(HERE, "..", "regrtest_data") class TestArgumentsManager: @@ -21,3 +25,25 @@ def test_help_message(linter: PyLinter) -> None: assert isinstance(linter.help_message, str) lines = linter.help_message.splitlines() assert lines[0] == "usage: pylint [-h]" + + +class TestOptionsProviderMixin: + """Tests for the argparse implementation of OptionsProviderMixin""" + + empty_module = join(REGRTEST_DATA_DIR, "empty.py") + + def test_logger_checker(self) -> None: + """Tests that we create Argument instances for the settings of the logger module""" + run = Run([self.empty_module], exit=False) + assert run.linter.namespace_test + assert len(run.linter.namespace_test) == 2 + + assert "logging-modules" in run.linter.namespace_test + logging_modules = run.linter.namespace_test["logging-modules"] + assert isinstance(logging_modules, config._Argument) + config._validate_argument(logging_modules) + + assert "logging-format-style" in run.linter.namespace_test + logging_format_style = run.linter.namespace_test["logging-format-style"] + assert isinstance(logging_format_style, config._Argument) + config._validate_argument(logging_format_style)