Skip to content

Commit 743e6a3

Browse files
committed
Add test for metadata mismatch (passes on main already)
1 parent f25f8ff commit 743e6a3

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/functional/test_download.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,8 @@ class Package:
12661266
metadata: MetadataKind
12671267
# This will override any dependencies specified in the actual dist's METADATA.
12681268
requires_dist: Tuple[str, ...] = ()
1269+
# This will override the Name specified in the actual dist's METADATA.
1270+
metadata_name: str = None
12691271

12701272
def metadata_filename(self) -> str:
12711273
"""This is specified by PEP 658."""
@@ -1296,7 +1298,7 @@ def generate_metadata(self) -> bytes:
12961298
return dedent(
12971299
f"""\
12981300
Metadata-Version: 2.1
1299-
Name: {self.name}
1301+
Name: {self.metadata_name or self.name}
13001302
Version: {self.version}
13011303
{self.requires_str()}
13021304
"""
@@ -1452,6 +1454,14 @@ def run_for_generated_index(
14521454
),
14531455
# This will raise an error when pip attempts to fetch the metadata file.
14541456
Package("simple2", "2.0", "simple2-2.0.tar.gz", MetadataKind.NoFile),
1457+
# This has a METADATA file with a mismatched name.
1458+
Package(
1459+
"simple2",
1460+
"3.0",
1461+
"simple2-3.0.tar.gz",
1462+
MetadataKind.Sha256,
1463+
metadata_name="not-simple2",
1464+
),
14551465
],
14561466
"colander": [
14571467
# Ensure we can read the dependencies from a metadata file within a wheel
@@ -1581,3 +1591,18 @@ def test_metadata_not_found(
15811591
f"ERROR: 404 Client Error: FileNotFoundError for url:.*{expected_re}"
15821592
)
15831593
assert pattern.search(result.stderr), (pattern, result.stderr)
1594+
1595+
1596+
def test_produces_error_for_mismatched_package_name_in_metadata(
1597+
download_generated_html_index: Callable[..., Tuple[TestPipResult, Path]],
1598+
) -> None:
1599+
"""Verify that the package name from the metadata matches the requested package."""
1600+
result, _ = download_generated_html_index(
1601+
_simple_packages,
1602+
["simple2==3.0"],
1603+
allow_error=True,
1604+
)
1605+
assert result.returncode != 0
1606+
assert (
1607+
"simple2-3.0.tar.gz has inconsistent Name: expected 'simple2', but metadata has 'not-simple2'"
1608+
) in result.stdout

0 commit comments

Comments
 (0)