blob: d8b6191153fc8a46361334e3ba014e299662cc4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
from __future__ import annotations
import os
from pathlib import Path
from pylint.lint.run import Run
from pylint.testutils.configuration_test import run_using_a_configuration_file
def check_configuration_file_reader(
runner: Run,
expected_disabled: set[str] | None = 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 == expected_jobs
assert bool(runner.linter.config.reports) == expected_reports_truthey
def test_can_read_toml_env_variable(tmp_path: Path, file_to_lint_path: str) -> None:
"""We can read and open a properly formatted toml file."""
config_file = tmp_path / "pyproject.toml"
config_file.write_text(
"""
[tool.pylint."messages control"]
disable = "logging-not-lazy,logging-format-interpolation"
jobs = "10"
reports = "yes"
"""
)
env_var = "tmp_path_env"
os.environ[env_var] = str(config_file)
mock_exit, _, runner = run_using_a_configuration_file(
f"${env_var}", file_to_lint_path
)
mock_exit.assert_called_once_with(0)
check_configuration_file_reader(runner)
|