Skip to content

Commit 84cb477

Browse files
committed
pylock: test file name validator
1 parent 501fe25 commit 84cb477

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/pip/_internal/models/pylock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def from_dict(cls, d: Dict[str, Any]) -> Self:
4343

4444

4545
def is_valid_pylock_file_name(path: Path) -> bool:
46-
return path.name == "pylock.toml" or bool(re.match(PYLOCK_FILE_NAME_RE, path.name))
46+
return path.name == "pylock.toml" or bool(PYLOCK_FILE_NAME_RE.match(path.name))
4747

4848

4949
def _toml_key(key: str) -> str:

tests/unit/test_pylock.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import pytest
24

35
from pip._vendor.packaging.markers import Marker
@@ -10,7 +12,21 @@
1012
PylockUnsupportedVersionError,
1113
PylockValidationError,
1214
_exactly_one,
15+
is_valid_pylock_file_name,
16+
)
17+
18+
19+
@pytest.mark.parametrize(
20+
"file_name,valid",
21+
[
22+
("pylock.toml", True),
23+
("pylock.spam.toml", True),
24+
("pylock.json", False),
25+
("pylock..toml", False),
26+
],
1327
)
28+
def test_pylock_file_name(file_name: str, valid: bool) -> None:
29+
assert is_valid_pylock_file_name(Path(file_name)) is valid
1430

1531

1632
def test_exactly_one() -> None:

0 commit comments

Comments
 (0)