Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_missing_key_error():
cache = PatchingCache(maxsize=100)
with pytest.raises(KeyError):
cache.retrieve("a", "b", True)
def test_store_retrieve():
cache = PatchingCache(maxsize=100)
cache.store("a", "b", True, "c")
assert cache.retrieve("a", "b", True) == "c"
assert cache.retrieve("c", "b", False) == "a"
def test_culling():
cache = PatchingCache(maxsize=4)
cache.store("a", "b", True, "c")
assert len(cache._cache) == 2
cache.store("a", "d", True, "e")
assert len(cache._cache) == 4
cache.store("a", "f", True, "g")
assert len(cache._cache) <= 4
def test_clear():
cache = PatchingCache(maxsize=100)
cache.store("a", "b", True, "c")
cache.clear()
with pytest.raises(KeyError):
cache.retrieve("a", "b", True)