Fixed #72 : Exception when get_results(id=10)
Fixed #74 : Keyword parameters are no longer recognized when a concept that redefines equality is created Fixed #118 : RecursionError: maximum recursion depth exceeded Fixed #119 : PreventCircularReferenceEvaluator Fixed #121 : Plural are not updated when new elements are added Fixed #123 : BaseCache : Values in cache can be evicted before being committed Fixed #105 : TOO_MANY_ERROR is not the relevant error when results are filtered
This commit is contained in:
Vendored
+46
-18
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from cache.BaseCache import MAX_INITIALIZED_KEY
|
||||
from cache.Cache import Cache
|
||||
from cache.CacheManager import CacheManager
|
||||
@@ -9,7 +10,6 @@ from cache.ListIfNeededCache import ListIfNeededCache
|
||||
from cache.SetCache import SetCache
|
||||
from core.concept import Concept
|
||||
from core.global_symbols import NotFound, Removed
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.cache import FakeSdp
|
||||
|
||||
@@ -65,21 +65,60 @@ class TestCache(TestUsingMemoryBasedSheerka):
|
||||
assert len(cache) == 2
|
||||
assert cache.copy() == {"key": "another value", "key2": "value2"}
|
||||
|
||||
def test_i_can_evict(self):
|
||||
def test_i_do_not_evict_when_put(self):
|
||||
maxsize = 5
|
||||
cache = Cache(max_size=5)
|
||||
|
||||
for key in range(maxsize):
|
||||
for key in range(maxsize + 2):
|
||||
cache.put(key, key)
|
||||
|
||||
assert len(cache) == maxsize + 2
|
||||
assert cache.copy() == {
|
||||
0: 0,
|
||||
1: 1,
|
||||
2: 2,
|
||||
3: 3,
|
||||
4: 4,
|
||||
5: 5,
|
||||
6: 6,
|
||||
}
|
||||
|
||||
def test_i_can_evict_when_get(self):
|
||||
maxsize = 5
|
||||
cache = Cache(max_size=5, default=lambda k: k)
|
||||
|
||||
for key in range(maxsize + 2):
|
||||
cache.get(key)
|
||||
|
||||
assert len(cache) == maxsize
|
||||
assert cache.has(0)
|
||||
assert cache.copy() == {
|
||||
2: 2,
|
||||
3: 3,
|
||||
4: 4,
|
||||
5: 5,
|
||||
6: 6,
|
||||
}
|
||||
|
||||
for key in range(maxsize, maxsize * 2):
|
||||
def test_i_do_not_evict_when_items_are_not_committed(self):
|
||||
maxsize = 5
|
||||
cache = Cache(max_size=5, default=lambda k: k)
|
||||
|
||||
for key in range(maxsize + 2):
|
||||
cache.put(key, key)
|
||||
|
||||
assert len(cache) == maxsize
|
||||
assert not cache.has(key - maxsize)
|
||||
assert len(cache) == maxsize + 2
|
||||
|
||||
cache.get(-1)
|
||||
assert len(cache) == maxsize + 2
|
||||
assert cache.copy() == {
|
||||
0: 0,
|
||||
1: 1,
|
||||
2: 2,
|
||||
3: 3,
|
||||
4: 4,
|
||||
5: 5,
|
||||
6: 6,
|
||||
}
|
||||
|
||||
def test_i_can_get_a_value_from_alt_sdp(self):
|
||||
cache = Cache(sdp=FakeSdp(get_value=lambda cache_name, key: NotFound)).auto_configure("cache_name")
|
||||
@@ -424,17 +463,6 @@ class TestCache(TestUsingMemoryBasedSheerka):
|
||||
assert cache.to_add == {"some_value"}
|
||||
assert cache.to_remove == {"some_other_value"}
|
||||
|
||||
def test_max_size_is_respected_when_populate(self):
|
||||
items = [("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5")]
|
||||
cache = Cache(max_size=3)
|
||||
|
||||
cache.populate(lambda: items, lambda item: item[0])
|
||||
|
||||
assert len(cache) == 3
|
||||
assert cache.get("3") == ("3", "3")
|
||||
assert cache.get("4") == ("4", "4")
|
||||
assert cache.get("5") == ("5", "5")
|
||||
|
||||
def test_i_can_get_all(self):
|
||||
items = [("1", "1"), ("2", "2"), ("3", "3")]
|
||||
cache = Cache()
|
||||
|
||||
Reference in New Issue
Block a user