Skip to content

Commit e9d46a9

Browse files
Introduce functional tests for configuration file
1 parent bb8a487 commit e9d46a9

15 files changed

+60
-70
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'load-plugins' : '[]' (bad-configuration-option-value)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'load-plugins' : '[]' (bad-configuration-option-value)
3+
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'disable' : 'logging-not-lazy,logging-format-interpolation' (bad-configuration-option-value)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'disable' : 'logging-not-lazy,logging-format-interpolation' (bad-configuration-option-value)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: E0013: Plugin 'pylint_websockets' is impossible to load, is it installed ? ('No module named 'pylint_websockets'') (bad-plugin-value)

tests/config/test_config_pyproject_toml.py

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from pathlib import Path
2+
from typing import Tuple
3+
from unittest.mock import patch
4+
5+
import pytest
6+
7+
from pylint import run_pylint
8+
9+
HERE = Path(__file__).parent
10+
USER_SPECIFIC = str(HERE.parent.parent)
11+
FUNCTIONAL_DIR = HERE / "functional"
12+
# We use string then recast to path so we can use -k in pytest otherwise
13+
# we get 'pyproject_toml_path0' as a test name
14+
TOML_PATHS = [str(p) for p in (FUNCTIONAL_DIR).rglob("*.toml")]
15+
FILE_TO_LINT = str(HERE / "file_to_lint.py")
16+
17+
18+
def get_relpath(path: str) -> str:
19+
"""Get the relative path we want without user specific information"""
20+
return path.replace(USER_SPECIFIC, "")[1:]
21+
22+
23+
def get_expected(pyproject_toml_path: str) -> Tuple[int, str]:
24+
expected_output = ""
25+
expected_code = 0
26+
expected_result_path = Path(pyproject_toml_path + ".expected")
27+
if expected_result_path.exists():
28+
expected_code = 2
29+
with open(expected_result_path, encoding="utf8") as f:
30+
expected_output = f.read()
31+
expected_output = expected_output.format(
32+
abspath=pyproject_toml_path, relpath=get_relpath(pyproject_toml_path)
33+
)
34+
return expected_code, expected_output
35+
36+
37+
@pytest.mark.parametrize("pyproject_toml_path", TOML_PATHS)
38+
def test_config_pyproject_toml(pyproject_toml_path, capsys):
39+
"""Functional tests for configurations."""
40+
msg = f"Wrong result with configuration {pyproject_toml_path}"
41+
expected_code, expected_output = get_expected(pyproject_toml_path)
42+
with patch(
43+
"sys.argv", ["pylint", "--rcfile", pyproject_toml_path, FILE_TO_LINT, "-r", "n"]
44+
):
45+
with pytest.raises(SystemExit) as exc_info:
46+
run_pylint()
47+
assert exc_info.value.code == expected_code, msg
48+
out, err = capsys.readouterr()
49+
# rstrip() applied so we can have a final newline in the expected test file
50+
assert expected_output.rstrip() == out.rstrip(), msg
51+
assert not err, msg

0 commit comments

Comments
 (0)