Skip to content

Commit fa87c9e

Browse files
itamarstpythonspeed
authored andcommitted
Testing for body methods of network cache.
1 parent c1ead0a commit fa87c9e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/pip/_internal/network/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def delete(self, key: str) -> None:
7070
path = self._get_cache_path(key)
7171
with suppressed_cache_errors():
7272
os.remove(path)
73+
with suppressed_cache_errors():
7374
os.remove(path + ".body")
7475

7576
def get_body(self, key: str) -> Optional[BinaryIO]:

tests/unit/test_network_cache.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def test_cache_roundtrip(self, cache_tmpdir: Path) -> None:
3131
cache.delete("test key")
3232
assert cache.get("test key") is None
3333

34+
def test_cache_roundtrip_body(self, cache_tmpdir: Path) -> None:
35+
cache = SafeFileCache(os.fspath(cache_tmpdir))
36+
assert cache.get_body("test key") is None
37+
cache.set_body("test key", b"a test string")
38+
assert cache.get_body("test key").read() == b"a test string"
39+
cache.delete("test key")
40+
assert cache.get_body("test key") is None
41+
3442
@pytest.mark.skipif("sys.platform == 'win32'")
3543
def test_safe_get_no_perms(
3644
self, cache_tmpdir: Path, monkeypatch: pytest.MonkeyPatch

0 commit comments

Comments
 (0)