Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pylint/testutils/functional/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def module(self) -> str:

@property
def expected_output(self) -> str:
output, _ = self._resolve_expected_output()
return output

@property
def expected_output_is_fallback(self) -> bool:
_, is_fallback = self._resolve_expected_output()
return is_fallback

def _resolve_expected_output(self) -> tuple[str, bool]:
files = [
p.stem
for p in Path(self._directory).glob(f"{split(self.base)[-1]}.[0-9]*.txt")
Expand All @@ -115,8 +124,11 @@ def expected_output(self) -> str:
for opt in sorted(output_options, reverse=True):
if _CURRENT_VERSION >= opt:
str_opt = "".join([str(s) for s in opt])
return join(self._directory, f"{self.base}.{str_opt}.txt")
return join(self._directory, self.base + ".txt")
return (
join(self._directory, f"{self.base}.{str_opt}.txt"),
_CURRENT_VERSION != opt,
)
return join(self._directory, self.base + ".txt"), False

@property
def source(self) -> str:
Expand Down
9 changes: 6 additions & 3 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def test_functional(
else:
actual_output = lint_test.check_messages()

golden_master.check(
lint_test.serialize_output(actual_output), test_file.expected_output
)
serialized_output = lint_test.serialize_output(actual_output)
if test_file.expected_output_is_fallback:
expected = Path(test_file.expected_output).read_text(encoding="utf-8")
assert serialized_output.rstrip() == expected.rstrip()
else:
golden_master.check(serialized_output, test_file.expected_output)
49 changes: 49 additions & 0 deletions tests/testutils/test_functional_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,55 @@ def test_expected_output_file_matching(files: list[str], output_file_name: str)
assert test_file.expected_output == f".{os.path.sep}{output_file_name}"


@pytest.mark.parametrize(
["files", "output_file_name", "is_fallback"],
[
([], "file.txt", False),
(["file.txt"], "file.txt", False),
(["file.315.txt"], "file.txt", False), # don't match 3.15
(["file.42.txt"], "file.txt", False), # don't match 4.2
(["file.32.txt", "file.txt"], "file.32.txt", True),
(["file.313.txt", "file.txt"], "file.313.txt", True),
(["file.314.txt", "file.txt"], "file.314.txt", False),
(
[
"file.310.txt",
"file.313.txt",
"file.312.txt",
"file.314.txt",
"file.txt",
],
"file.314.txt",
False,
),
(
["file.310.txt", "file.313.txt", "file.312.txt", "file.txt"],
"file.313.txt",
True,
),
# don't match other test file names accidentally
([".file.313.txt"], "file.txt", False),
(["file_other.313.txt"], "file.txt", False),
(["other_file.313.txt"], "file.txt", False),
],
)
def test_expected_output_fallback_detection(
files: list[str], output_file_name: str, is_fallback: bool
) -> None:
"""Test output file fallback detection. Pin current Python version to 3.13."""
with tempdir():
for file in files:
with open(file, "w", encoding="utf-8"):
...
test_file = FunctionalTestFile(".", "file.py")
with patch(
"pylint.testutils.functional.test_file._CURRENT_VERSION",
new=(3, 14),
):
assert test_file.expected_output == f".{os.path.sep}{output_file_name}"
assert test_file.expected_output_is_fallback is is_fallback


def test_minimal_messages_config_enabled(pytest_config: MagicMock) -> None:
"""Test that all messages not targeted in the functional test are disabled
when running with --minimal-messages-config.
Expand Down
Loading