|
| 1 | +import os |
| 2 | + |
1 | 3 | from pip._internal.cache import WheelCache
|
| 4 | +from pip._internal.models.format_control import FormatControl |
| 5 | +from pip._internal.models.link import Link |
2 | 6 | from pip._internal.utils.compat import expanduser
|
| 7 | +from pip._internal.utils.misc import ensure_dir |
| 8 | + |
| 9 | + |
| 10 | +def test_expands_path(): |
| 11 | + wc = WheelCache("~/.foo/", None) |
| 12 | + assert wc.cache_dir == expanduser("~/.foo/") |
| 13 | + |
| 14 | + |
| 15 | +def test_falsey_path_none(): |
| 16 | + wc = WheelCache(False, None) |
| 17 | + assert wc.cache_dir is None |
3 | 18 |
|
4 | 19 |
|
5 |
| -class TestWheelCache: |
| 20 | +def test_subdirectory_fragment(): |
| 21 | + """ |
| 22 | + Test the subdirectory URL fragment is part of the cache key. |
| 23 | + """ |
| 24 | + wc = WheelCache("~/.foo/", None) |
| 25 | + link1 = Link("git+https://g.c/o/r#subdirectory=d1") |
| 26 | + link2 = Link("git+https://g.c/o/r#subdirectory=d2") |
| 27 | + assert wc.get_path_for_link(link1) != wc.get_path_for_link(link2) |
6 | 28 |
|
7 |
| - def test_expands_path(self): |
8 |
| - wc = WheelCache("~/.foo/", None) |
9 |
| - assert wc.cache_dir == expanduser("~/.foo/") |
10 | 29 |
|
11 |
| - def test_falsey_path_none(self): |
12 |
| - wc = WheelCache(False, None) |
13 |
| - assert wc.cache_dir is None |
| 30 | +def test_wheel_name_filter(tmpdir): |
| 31 | + """ |
| 32 | + Test the wheel cache filters on wheel name when several wheels |
| 33 | + for different package are stored under the same cache directory. |
| 34 | + """ |
| 35 | + wc = WheelCache(tmpdir, FormatControl()) |
| 36 | + link = Link("https://g.c/package.tar.gz") |
| 37 | + cache_path = wc.get_path_for_link(link) |
| 38 | + ensure_dir(cache_path) |
| 39 | + with open(os.path.join(cache_path, "package-1.0-py3-none-any.whl"), "w"): |
| 40 | + pass |
| 41 | + # package matches wheel name |
| 42 | + assert wc.get(link, "package", [("py3", "none", "any")]) is not link |
| 43 | + # package2 does not match wheel name |
| 44 | + assert wc.get(link, "package2", [("py3", "none", "any")]) is link |
0 commit comments