diff options
| author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-11-09 15:04:26 +0100 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-11-09 15:07:43 +0100 |
| commit | 3e87888e66babd1c1de06a334297a82988e7dfc7 (patch) | |
| tree | dd3a52a51c4ad0a3aca5d3c8d30465f26d44a3c5 | |
| parent | 7706e7ef3a2f06b7a16dd1127581270d2d7be641 (diff) | |
| download | pylint-git-3e87888e66babd1c1de06a334297a82988e7dfc7.tar.gz | |
Refactor 'check_configuration_file_reader' so we can assert other files
Necessary prior to #4720
| -rw-r--r-- | tests/config/test_config.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/tests/config/test_config.py b/tests/config/test_config.py index fd0c87e23..921826702 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -8,10 +8,10 @@ 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 +22,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=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 +53,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 +69,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 +85,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 +105,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 +122,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) |
