Skip to content
Closed
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
2 changes: 1 addition & 1 deletion check-peps.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def _validate_python_version(line_num: int, line: str) -> MessageIterator:
yield line_num, f"Python-Version minor part must not have leading zeros: {version}"

if micro == "":
return
continue
if minor == "x":
yield line_num, f"Python-Version micro part must be empty if minor part is 'x': {version}"
elif micro[0] == "0":
Expand Down
38 changes: 38 additions & 0 deletions pep_sphinx_extensions/tests/pep_lint/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,41 @@ def test_validate_python_version(line: str, expected_warnings: set):
assert warnings == [], warnings

assert found_warnings == expected_warnings


@pytest.mark.parametrize(
("line", "expected_warnings"),
[
# Every version in the header must be validated, not just the first.
# A version without a micro part used to end validation early.
("3.0, 3.a", ["Python-Version minor part must be numeric: 3.a"]),
("3.12, 4.0", ["Python-Version major part must be 1, 2, or 3: 4.0"]),
(
"3.11, 3.x.1",
["Python-Version micro part must be empty if minor part is 'x': 3.x.1"],
),
(
"3.9, 3.09",
["Python-Version minor part must not have leading zeros: 3.09"],
),
(
"3.a, 4.b",
[
"Python-Version minor part must be numeric: 3.a",
"Python-Version major part must be 1, 2, or 3: 4.b",
"Python-Version minor part must be numeric: 4.b",
],
),
# valid lists stay silent
("3.0, 3.1, 3.14", []),
("1.5.2, 2.7.18, 3.13.1", []),
],
# call str() on each parameterised value in the test ID.
ids=str,
)
def test_validate_python_version_all_versions(line: str, expected_warnings: list):
warnings = [
warning for (_, warning) in check_peps._validate_python_version(1, line)
]

assert warnings == expected_warnings, warnings
Loading