8
8
from pylint .lint .run import Run
9
9
10
10
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"""
15
15
args = ["--rcfile" , str (config_file ), __file__ ]
16
16
# If we used `pytest.raises(SystemExit)`, the `runner` variable
17
17
# would not be accessible outside the `with` block.
@@ -22,16 +22,24 @@ def check_configuration_file_reader(config_file: Union[str, Path]) -> Run:
22
22
# in `_msg_states`, used by `is_message_enabled`.
23
23
with unittest .mock .patch ("pylint.lint.pylinter.check_parallel" ):
24
24
runner = pylint .lint .Run (args )
25
+ mocked_exit .assert_called_once_with (expected_exit_code )
26
+ return runner
27
+
25
28
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" }
28
39
for msgid in expected_disabled :
29
40
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
35
43
36
44
37
45
def test_can_read_ini (tmp_path : Path ) -> None :
@@ -45,7 +53,8 @@ def test_can_read_ini(tmp_path: Path) -> None:
45
53
reports = yes
46
54
"""
47
55
)
48
- check_configuration_file_reader (config_file )
56
+ run = get_runner_from_config_file (config_file )
57
+ check_configuration_file_reader (run )
49
58
50
59
51
60
def test_can_read_setup_cfg (tmp_path : Path ) -> None :
@@ -60,7 +69,8 @@ def test_can_read_setup_cfg(tmp_path: Path) -> None:
60
69
reports = yes
61
70
"""
62
71
)
63
- check_configuration_file_reader (config_file )
72
+ run = get_runner_from_config_file (config_file )
73
+ check_configuration_file_reader (run )
64
74
65
75
66
76
def test_can_read_toml (tmp_path : Path ) -> None :
@@ -75,7 +85,8 @@ def test_can_read_toml(tmp_path: Path) -> None:
75
85
reports = "yes"
76
86
"""
77
87
)
78
- check_configuration_file_reader (config_file )
88
+ run = get_runner_from_config_file (config_file )
89
+ check_configuration_file_reader (run )
79
90
80
91
81
92
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:
94
105
reports = true
95
106
"""
96
107
)
97
- check_configuration_file_reader (config_file )
108
+ run = get_runner_from_config_file (config_file )
109
+ check_configuration_file_reader (run )
98
110
99
111
100
112
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:
110
122
)
111
123
env_var = "tmp_path_env"
112
124
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