|
7 | 7 | from pip._vendor.cachecontrol.caches import FileCache
|
8 | 8 |
|
9 | 9 | from pip._internal.network.cache import SafeFileCache
|
| 10 | +from tests.lib.filesystem import chmod |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @pytest.fixture(scope="function")
|
@@ -57,26 +58,23 @@ def test_cache_roundtrip_body(self, cache_tmpdir: Path) -> None:
|
57 | 58 | def test_safe_get_no_perms(
|
58 | 59 | self, cache_tmpdir: Path, monkeypatch: pytest.MonkeyPatch
|
59 | 60 | ) -> None:
|
60 |
| - os.chmod(cache_tmpdir, 000) |
61 |
| - |
62 | 61 | monkeypatch.setattr(os.path, "exists", lambda x: True)
|
63 | 62 |
|
64 |
| - cache = SafeFileCache(os.fspath(cache_tmpdir)) |
65 |
| - cache.get("foo") |
| 63 | + with chmod(cache_tmpdir, 000): |
| 64 | + cache = SafeFileCache(os.fspath(cache_tmpdir)) |
| 65 | + cache.get("foo") |
66 | 66 |
|
67 | 67 | @pytest.mark.skipif("sys.platform == 'win32'")
|
68 | 68 | def test_safe_set_no_perms(self, cache_tmpdir: Path) -> None:
|
69 |
| - os.chmod(cache_tmpdir, 000) |
70 |
| - |
71 |
| - cache = SafeFileCache(os.fspath(cache_tmpdir)) |
72 |
| - cache.set("foo", b"bar") |
| 69 | + with chmod(cache_tmpdir, 000): |
| 70 | + cache = SafeFileCache(os.fspath(cache_tmpdir)) |
| 71 | + cache.set("foo", b"bar") |
73 | 72 |
|
74 | 73 | @pytest.mark.skipif("sys.platform == 'win32'")
|
75 | 74 | def test_safe_delete_no_perms(self, cache_tmpdir: Path) -> None:
|
76 |
| - os.chmod(cache_tmpdir, 000) |
77 |
| - |
78 |
| - cache = SafeFileCache(os.fspath(cache_tmpdir)) |
79 |
| - cache.delete("foo") |
| 75 | + with chmod(cache_tmpdir, 000): |
| 76 | + cache = SafeFileCache(os.fspath(cache_tmpdir)) |
| 77 | + cache.delete("foo") |
80 | 78 |
|
81 | 79 | def test_cache_hashes_are_same(self, cache_tmpdir: Path) -> None:
|
82 | 80 | cache = SafeFileCache(os.fspath(cache_tmpdir))
|
|
0 commit comments