Skip to content

Commit 1de6cf0

Browse files
authored
Merge pull request #11713 from uranusjr/fix-link-hashes-tests
Test and news for wheel cache restoration
2 parents c20c789 + 5eda50d commit 1de6cf0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

news/11527.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Wheel cache behavior is restored to match previous versions, allowing the
2+
cache to find existing entries.

tests/unit/test_cache.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from pathlib import Path
33

4-
from pip._vendor.packaging.tags import Tag
4+
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
55

66
from pip._internal.cache import WheelCache, _hash_dict
77
from pip._internal.models.format_control import FormatControl
@@ -52,6 +52,48 @@ def test_cache_hash() -> None:
5252
assert h == "f83b32dfa27a426dec08c21bf006065dd003d0aac78e7fc493d9014d"
5353

5454

55+
def test_link_to_cache(tmpdir: Path) -> None:
56+
"""
57+
Test that Link.from_json() produces Links with consistent cache
58+
locations
59+
"""
60+
wc = WheelCache(os.fspath(tmpdir), FormatControl())
61+
# Define our expectations for stable cache path.
62+
i_name = interpreter_name()
63+
i_version = interpreter_version()
64+
key_parts = {
65+
"url": "https://files.pythonhosted.org/packages/a6/91/"
66+
"86a6eac449ddfae239e93ffc1918cf33fd9bab35c04d1e963b311e347a73/"
67+
"netifaces-0.11.0.tar.gz",
68+
"sha256": "043a79146eb2907edf439899f262b3dfe41717d34124298ed281139a8b93ca32",
69+
"interpreter_name": i_name,
70+
"interpreter_version": i_version,
71+
}
72+
expected_hash = _hash_dict(key_parts)
73+
parts = [
74+
expected_hash[:2],
75+
expected_hash[2:4],
76+
expected_hash[4:6],
77+
expected_hash[6:],
78+
]
79+
pathed_hash = os.path.join(*parts)
80+
# Check working from a Link produces the same result.
81+
file_data = {
82+
"filename": "netifaces-0.11.0.tar.gz",
83+
"hashes": {
84+
"sha256": key_parts["sha256"],
85+
},
86+
"requires-python": "",
87+
"url": key_parts["url"],
88+
"yanked": False,
89+
}
90+
page_url = "https://pypi.org/simple/netifaces/"
91+
link = Link.from_json(file_data=file_data, page_url=page_url)
92+
assert link
93+
path = wc.get_path_for_link(link)
94+
assert pathed_hash in path
95+
96+
5597
def test_get_cache_entry(tmpdir: Path) -> None:
5698
wc = WheelCache(os.fspath(tmpdir), FormatControl())
5799
persi_link = Link("https://g.c/o/r/persi")

0 commit comments

Comments
 (0)