Skip to content

Commit 6151e00

Browse files
committed
fix(tests): update mocking in cache tests
1 parent d588393 commit 6151e00

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/grizzly/common/test_cache.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,28 @@
99

1010
def test_cache_active_cache(mocker, tmp_path):
1111
"""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")
1416
# create path
1517
mocker.patch("grizzly.common.cache._ACTIVE_CACHE", new=None)
1618
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
2021
# find existing with expired entry
2122
mocker.patch("grizzly.common.cache._ACTIVE_CACHE", new=None)
22-
(tmp_path / "0").mkdir()
23+
(cache_path / "0").mkdir()
2324
found_path = _active_cache()
2425
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
3026

3127

3228
def test_cache_basic(mocker, tmp_path):
3329
"""test basic cache functionality"""
34-
mocker.patch("grizzly.common.cache.CACHE_PATH", new=tmp_path)
35-
mocker.patch("grizzly.common.cache.InterProcessLock")
3630
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")
3734
# attempt to clear empty cache
3835
clear_cached()
3936
# invalid keys
@@ -68,6 +65,6 @@ def test_cache_basic(mocker, tmp_path):
6865
# clear with nothing expired
6966
clear_cached()
7067
assert find_cached("test-key") is not None
71-
# clear with expired
68+
# clear with everything expired
7269
clear_cached(max_age=0)
7370
assert find_cached("test-key") is None

0 commit comments

Comments
 (0)