summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-09 15:04:26 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-10 00:01:52 +0100
commit34eeaf01330414cafad3fbcc8298953f265645be (patch)
tree71fe3aca5bf1021083f918ad45162cbad4077067
parent96a7d1d147d33ec5b15047d5ca71ee402f51b08d (diff)
downloadpylint-git-34eeaf01330414cafad3fbcc8298953f265645be.tar.gz
Refactor 'check_configuration_file_reader' so we can assert other files
Necessary prior to #4720
-rw-r--r--tests/config/test_config.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index fd0c87e23..37bd519b6 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -2,16 +2,15 @@
import os
import unittest.mock
from pathlib import Path
-from typing import Union
+from typing import Optional, Set, Union
import pylint.lint
from pylint.lint.run import Run
-
-def check_configuration_file_reader(config_file: Union[str, Path]) -> Run:
- """Initialize pylint with the given configuration file and check that
- what we initialized the linter with what was expected.
- """
+def get_runner_from_config_file(
+ config_file: Union[str, Path], expected_exit_code: int = 0
+) -> Run:
+ """Initialize pylint with the given configuration file and return the Run"""
args = ["--rcfile", str(config_file), __file__]
# If we used `pytest.raises(SystemExit)`, the `runner` variable
# would not be accessible outside the `with` block.
@@ -22,16 +21,24 @@ def check_configuration_file_reader(config_file: Union[str, Path]) -> Run:
# in `_msg_states`, used by `is_message_enabled`.
with unittest.mock.patch("pylint.lint.pylinter.check_parallel"):
runner = pylint.lint.Run(args)
+ mocked_exit.assert_called_once_with(expected_exit_code)
+ return runner
+
- # "logging-not-lazy" and "logging-format-interpolation"
- expected_disabled = {"W1201", "W1202"}
+def check_configuration_file_reader(
+ runner: Run,
+ expected_disabled: Optional[Set[str]] = None,
+ expected_jobs: int = 10,
+ expected_reports_truthey: bool = True,
+) -> None:
+ """Check that what we initialized the linter with what was expected."""
+ if expected_disabled is None:
+ # "logging-not-lazy" and "logging-format-interpolation"
+ expected_disabled = {"W1201", "W1202"}
for msgid in expected_disabled:
assert not runner.linter.is_message_enabled(msgid)
- assert runner.linter.config.jobs == 10
- assert runner.linter.config.reports
-
- mocked_exit.assert_called_once_with(0)
- return runner
+ assert runner.linter.config.jobs == expected_jobs
+ assert bool(runner.linter.config.reports) == expected_reports_truthey
def test_can_read_ini(tmp_path: Path) -> None:
@@ -45,7 +52,8 @@ jobs = 10
reports = yes
"""
)
- check_configuration_file_reader(config_file)
+ run = get_runner_from_config_file(config_file)
+ check_configuration_file_reader(run)
def test_can_read_setup_cfg(tmp_path: Path) -> None:
@@ -60,7 +68,8 @@ jobs = 10
reports = yes
"""
)
- check_configuration_file_reader(config_file)
+ run = get_runner_from_config_file(config_file)
+ check_configuration_file_reader(run)
def test_can_read_toml(tmp_path: Path) -> None:
@@ -75,7 +84,8 @@ jobs = "10"
reports = "yes"
"""
)
- check_configuration_file_reader(config_file)
+ run = get_runner_from_config_file(config_file)
+ check_configuration_file_reader(run)
def test_can_read_toml_rich_types(tmp_path: Path) -> None:
@@ -94,7 +104,8 @@ jobs = 10
reports = true
"""
)
- check_configuration_file_reader(config_file)
+ run = get_runner_from_config_file(config_file)
+ check_configuration_file_reader(run)
def test_can_read_toml_env_variable(tmp_path: Path) -> None:
@@ -110,4 +121,5 @@ reports = "yes"
)
env_var = "tmp_path_env"
os.environ[env_var] = str(config_file)
- check_configuration_file_reader(f"${env_var}")
+ run = get_runner_from_config_file(f"${env_var}")
+ check_configuration_file_reader(run)