|
9 | 9 |
|
10 | 10 | def test_cache_active_cache(mocker, tmp_path): |
11 | 11 | """test _active_cache()""" |
12 | | - mocker.patch("grizzly.common.cache.CACHE_PATH", new=tmp_path) |
13 | | - fake_ipl = mocker.patch("grizzly.common.cache.InterProcessLock") |
| 12 | + cache_path = tmp_path / "cache" |
| 13 | + cache_path.mkdir() |
| 14 | + mocker.patch("grizzly.common.cache.CACHE_PATH", new=cache_path) |
| 15 | + mocker.patch("grizzly.common.cache.LOCK_FILE", new=tmp_path / "cache.lock") |
14 | 16 | # create path |
15 | 17 | mocker.patch("grizzly.common.cache._ACTIVE_CACHE", new=None) |
16 | 18 | new_path = _active_cache() |
17 | | - assert any(tmp_path.iterdir()) |
18 | | - assert tmp_path in new_path.parents |
19 | | - assert fake_ipl.call_count == 1 |
| 19 | + assert any(cache_path.iterdir()) |
| 20 | + assert cache_path in new_path.parents |
20 | 21 | # find existing with expired entry |
21 | 22 | mocker.patch("grizzly.common.cache._ACTIVE_CACHE", new=None) |
22 | | - (tmp_path / "0").mkdir() |
| 23 | + (cache_path / "0").mkdir() |
23 | 24 | found_path = _active_cache() |
24 | 25 | assert found_path == new_path |
25 | | - assert fake_ipl.call_count == 2 |
26 | | - # use cached value |
27 | | - found_path = _active_cache() |
28 | | - assert found_path == new_path |
29 | | - assert fake_ipl.call_count == 2 |
30 | 26 |
|
31 | 27 |
|
32 | 28 | def test_cache_basic(mocker, tmp_path): |
33 | 29 | """test basic cache functionality""" |
34 | | - mocker.patch("grizzly.common.cache.CACHE_PATH", new=tmp_path) |
35 | | - mocker.patch("grizzly.common.cache.InterProcessLock") |
36 | 30 | mocker.patch("grizzly.common.cache._ACTIVE_CACHE", new=None) |
| 31 | + (tmp_path / "cache").mkdir() |
| 32 | + mocker.patch("grizzly.common.cache.CACHE_PATH", new=tmp_path / "cache") |
| 33 | + mocker.patch("grizzly.common.cache.LOCK_FILE", new=tmp_path / "cache.lock") |
37 | 34 | # attempt to clear empty cache |
38 | 35 | clear_cached() |
39 | 36 | # invalid keys |
@@ -68,6 +65,6 @@ def test_cache_basic(mocker, tmp_path): |
68 | 65 | # clear with nothing expired |
69 | 66 | clear_cached() |
70 | 67 | assert find_cached("test-key") is not None |
71 | | - # clear with expired |
| 68 | + # clear with everything expired |
72 | 69 | clear_cached(max_age=0) |
73 | 70 | assert find_cached("test-key") is None |
0 commit comments