Skip to content

Commit

Permalink
Set future_option_parsing=True for logging and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Dec 22, 2021
1 parent a329ede commit b9b957a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pylint/checkers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 27 additions & 1 deletion tests/config/test_argparse_config.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)

0 comments on commit b9b957a

Please sign in to comment.