Skip to content

Commit 3e87888

Browse files
Refactor 'check_configuration_file_reader' so we can assert other files
Necessary prior to #4720
1 parent 7706e7e commit 3e87888

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

tests/config/test_config.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from pylint.lint.run import Run
99

1010

11-
def check_configuration_file_reader(config_file: Union[str, Path]) -> Run:
12-
"""Initialize pylint with the given configuration file and check that
13-
what we initialized the linter with what was expected.
14-
"""
11+
def get_runner_from_config_file(
12+
config_file: Union[str, Path], expected_exit_code: int = 0
13+
) -> Run:
14+
"""Initialize pylint with the given configuration file and return the Run"""
1515
args = ["--rcfile", str(config_file), __file__]
1616
# If we used `pytest.raises(SystemExit)`, the `runner` variable
1717
# would not be accessible outside the `with` block.
@@ -22,16 +22,24 @@ def check_configuration_file_reader(config_file: Union[str, Path]) -> Run:
2222
# in `_msg_states`, used by `is_message_enabled`.
2323
with unittest.mock.patch("pylint.lint.pylinter.check_parallel"):
2424
runner = pylint.lint.Run(args)
25+
mocked_exit.assert_called_once_with(expected_exit_code)
26+
return runner
27+
2528

26-
# "logging-not-lazy" and "logging-format-interpolation"
27-
expected_disabled = {"W1201", "W1202"}
29+
def check_configuration_file_reader(
30+
runner: Run,
31+
expected_disabled=None,
32+
expected_jobs: int = 10,
33+
expected_reports_truthey: bool = True,
34+
) -> None:
35+
"""Check that what we initialized the linter with what was expected."""
36+
if expected_disabled is None:
37+
# "logging-not-lazy" and "logging-format-interpolation"
38+
expected_disabled = {"W1201", "W1202"}
2839
for msgid in expected_disabled:
2940
assert not runner.linter.is_message_enabled(msgid)
30-
assert runner.linter.config.jobs == 10
31-
assert runner.linter.config.reports
32-
33-
mocked_exit.assert_called_once_with(0)
34-
return runner
41+
assert runner.linter.config.jobs == expected_jobs
42+
assert bool(runner.linter.config.reports) == expected_reports_truthey
3543

3644

3745
def test_can_read_ini(tmp_path: Path) -> None:
@@ -45,7 +53,8 @@ def test_can_read_ini(tmp_path: Path) -> None:
4553
reports = yes
4654
"""
4755
)
48-
check_configuration_file_reader(config_file)
56+
run = get_runner_from_config_file(config_file)
57+
check_configuration_file_reader(run)
4958

5059

5160
def test_can_read_setup_cfg(tmp_path: Path) -> None:
@@ -60,7 +69,8 @@ def test_can_read_setup_cfg(tmp_path: Path) -> None:
6069
reports = yes
6170
"""
6271
)
63-
check_configuration_file_reader(config_file)
72+
run = get_runner_from_config_file(config_file)
73+
check_configuration_file_reader(run)
6474

6575

6676
def test_can_read_toml(tmp_path: Path) -> None:
@@ -75,7 +85,8 @@ def test_can_read_toml(tmp_path: Path) -> None:
7585
reports = "yes"
7686
"""
7787
)
78-
check_configuration_file_reader(config_file)
88+
run = get_runner_from_config_file(config_file)
89+
check_configuration_file_reader(run)
7990

8091

8192
def test_can_read_toml_rich_types(tmp_path: Path) -> None:
@@ -94,7 +105,8 @@ def test_can_read_toml_rich_types(tmp_path: Path) -> None:
94105
reports = true
95106
"""
96107
)
97-
check_configuration_file_reader(config_file)
108+
run = get_runner_from_config_file(config_file)
109+
check_configuration_file_reader(run)
98110

99111

100112
def test_can_read_toml_env_variable(tmp_path: Path) -> None:
@@ -110,4 +122,5 @@ def test_can_read_toml_env_variable(tmp_path: Path) -> None:
110122
)
111123
env_var = "tmp_path_env"
112124
os.environ[env_var] = str(config_file)
113-
check_configuration_file_reader(f"${env_var}")
125+
run = get_runner_from_config_file(f"${env_var}")
126+
check_configuration_file_reader(run)

0 commit comments

Comments
 (0)