Skip to content

Commit 5f0dd4c

Browse files
committed
Add regression test for canonicalized package names for PEP658 metadata
1 parent 743e6a3 commit 5f0dd4c

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

tests/functional/test_download.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from hashlib import sha256
99
from pathlib import Path
1010
from textwrap import dedent
11-
from typing import Callable, Dict, List, Tuple
11+
from typing import Callable, Dict, List, Optional, Tuple
1212

1313
import pytest
1414

@@ -1267,7 +1267,7 @@ class Package:
12671267
# This will override any dependencies specified in the actual dist's METADATA.
12681268
requires_dist: Tuple[str, ...] = ()
12691269
# This will override the Name specified in the actual dist's METADATA.
1270-
metadata_name: str = None
1270+
metadata_name: Optional[str] = None
12711271

12721272
def metadata_filename(self) -> str:
12731273
"""This is specified by PEP 658."""
@@ -1501,6 +1501,16 @@ def run_for_generated_index(
15011501
"priority", "1.0", "priority-1.0-py2.py3-none-any.whl", MetadataKind.NoFile
15021502
),
15031503
],
1504+
"requires-simple-extra": [
1505+
# Metadata name is not canonicalized.
1506+
Package(
1507+
"requires-simple-extra",
1508+
"0.1",
1509+
"requires_simple_extra-0.1-py2.py3-none-any.whl",
1510+
MetadataKind.Sha256,
1511+
metadata_name="Requires_Simple.Extra",
1512+
),
1513+
],
15041514
}
15051515

15061516

@@ -1604,5 +1614,34 @@ def test_produces_error_for_mismatched_package_name_in_metadata(
16041614
)
16051615
assert result.returncode != 0
16061616
assert (
1607-
"simple2-3.0.tar.gz has inconsistent Name: expected 'simple2', but metadata has 'not-simple2'"
1617+
"simple2-3.0.tar.gz has inconsistent Name: expected 'simple2', but metadata "
1618+
"has 'not-simple2'"
16081619
) in result.stdout
1620+
1621+
1622+
@pytest.mark.parametrize(
1623+
"requirement",
1624+
(
1625+
"requires-simple-extra==0.1",
1626+
"REQUIRES_SIMPLE-EXTRA==0.1",
1627+
"REQUIRES....simple-_-EXTRA==0.1",
1628+
),
1629+
)
1630+
def test_canonicalizes_package_name_before_verifying_metadata(
1631+
download_generated_html_index: Callable[..., Tuple[TestPipResult, Path]],
1632+
requirement: str,
1633+
) -> None:
1634+
"""Verify that the package name from the command line and the package's
1635+
METADATA are both canonicalized before comparison.
1636+
1637+
Regression test for https://github.com/pypa/pip/issues/12038
1638+
"""
1639+
result, download_dir = download_generated_html_index(
1640+
_simple_packages,
1641+
[requirement],
1642+
allow_error=True,
1643+
)
1644+
assert result.returncode == 0
1645+
assert os.listdir(download_dir) == [
1646+
"requires_simple_extra-0.1-py2.py3-none-any.whl",
1647+
]

0 commit comments

Comments
 (0)