|
8 | 8 | from hashlib import sha256
|
9 | 9 | from pathlib import Path
|
10 | 10 | from textwrap import dedent
|
11 |
| -from typing import Callable, Dict, List, Tuple |
| 11 | +from typing import Callable, Dict, List, Optional, Tuple |
12 | 12 |
|
13 | 13 | import pytest
|
14 | 14 |
|
@@ -1267,7 +1267,7 @@ class Package:
|
1267 | 1267 | # This will override any dependencies specified in the actual dist's METADATA.
|
1268 | 1268 | requires_dist: Tuple[str, ...] = ()
|
1269 | 1269 | # This will override the Name specified in the actual dist's METADATA.
|
1270 |
| - metadata_name: str = None |
| 1270 | + metadata_name: Optional[str] = None |
1271 | 1271 |
|
1272 | 1272 | def metadata_filename(self) -> str:
|
1273 | 1273 | """This is specified by PEP 658."""
|
@@ -1501,6 +1501,16 @@ def run_for_generated_index(
|
1501 | 1501 | "priority", "1.0", "priority-1.0-py2.py3-none-any.whl", MetadataKind.NoFile
|
1502 | 1502 | ),
|
1503 | 1503 | ],
|
| 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 | + ], |
1504 | 1514 | }
|
1505 | 1515 |
|
1506 | 1516 |
|
@@ -1604,5 +1614,34 @@ def test_produces_error_for_mismatched_package_name_in_metadata(
|
1604 | 1614 | )
|
1605 | 1615 | assert result.returncode != 0
|
1606 | 1616 | 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'" |
1608 | 1619 | ) 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