|
1 | 1 | import os
|
2 | 2 | from pathlib import Path
|
3 | 3 |
|
4 |
| -from pip._vendor.packaging.tags import Tag |
| 4 | +from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version |
5 | 5 |
|
6 | 6 | from pip._internal.cache import WheelCache, _hash_dict
|
7 | 7 | from pip._internal.models.format_control import FormatControl
|
@@ -52,6 +52,48 @@ def test_cache_hash() -> None:
|
52 | 52 | assert h == "f83b32dfa27a426dec08c21bf006065dd003d0aac78e7fc493d9014d"
|
53 | 53 |
|
54 | 54 |
|
| 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 | + |
55 | 97 | def test_get_cache_entry(tmpdir: Path) -> None:
|
56 | 98 | wc = WheelCache(os.fspath(tmpdir), FormatControl())
|
57 | 99 | persi_link = Link("https://g.c/o/r/persi")
|
|
0 commit comments