Skip to content

Commit ca8a6e4

Browse files
Add tests for testutils.configuration_test.get_expected_output
1 parent 6de717a commit ca8a6e4

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

pylint/testutils/configuration_test.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020

2121
def get_expected_or_default(
22-
tested_configuration_file: str, suffix: str, default: ConfigurationValue
22+
tested_configuration_file: Union[str, Path],
23+
suffix: str,
24+
default: ConfigurationValue,
2325
) -> str:
2426
"""Return the expected value from the file if it exists, or the given default."""
2527
expected = default
@@ -67,18 +69,18 @@ def get_expected_configuration(
6769

6870

6971
def get_expected_output(
70-
configuration_path: str, user_specific_path: Path
72+
configuration_path: Union[str, Path], user_specific_path: Path
7173
) -> Tuple[int, str]:
7274
"""Get the expected output of a functional test."""
7375

7476
def get_related_files(
75-
tested_configuration_file: str, suffix_filter: str
77+
tested_configuration_file: Union[str, Path], suffix_filter: str
7678
) -> List[Path]:
77-
path = Path(tested_configuration_file)
79+
conf_path = Path(tested_configuration_file)
7880
return [
7981
p
80-
for p in path.parent.iterdir()
81-
if path.stem in str(p) and str(p).endswith(suffix_filter)
82+
for p in conf_path.parent.iterdir()
83+
if str(p.stem).startswith(conf_path.stem) and str(p).endswith(suffix_filter)
8284
]
8385

8486
exit_code = 0

tests/testutils/data/t.3.out

Whitespace-only changes.

tests/testutils/data/t.out

Whitespace-only changes.

tests/testutils/data/t.toml

Whitespace-only changes.

tests/testutils/data/u.out

Whitespace-only changes.

tests/testutils/data/u.toml

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
from pathlib import Path
3+
4+
from pytest import LogCaptureFixture
5+
6+
from pylint.testutils.configuration_test import get_expected_output
7+
8+
HERE = Path(__file__).parent
9+
USER_SPECIFIC_PATH = HERE.parent.parent
10+
DATA_DIRECTORY = HERE / "data"
11+
12+
13+
def test_get_expected_output(caplog: LogCaptureFixture) -> None:
14+
caplog.set_level(logging.INFO)
15+
exit_code, _ = get_expected_output(DATA_DIRECTORY / "t.toml", USER_SPECIFIC_PATH)
16+
assert "Too much .out files" in str(caplog.text)
17+
assert exit_code == -1
18+
exit_code, _ = get_expected_output(DATA_DIRECTORY / "u.toml", USER_SPECIFIC_PATH)
19+
assert exit_code == -1
20+
assert "Wrong format for .out file name" in str(caplog.text)
21+
exit_code, _ = get_expected_output(DATA_DIRECTORY / "v.toml", USER_SPECIFIC_PATH)
22+
assert exit_code == 0
23+
assert ".out file does not exists" in str(caplog.text)

0 commit comments

Comments
 (0)