def test_tilecache_can_clear(): cache = TileCache(None, None) key = 1 value = 1 assert len(cache) == 0 cache[key] = value assert len(cache) == 1 cache.clear() assert len(cache) == 0
def test_tilecache_lru(): cache = TileCache(None, None) cache[1] = 1 cache[2] = 2 val = cache[1] assert val == 1 assert list(cache) == [2, 1]
def test_tilecache_can_constrain_len(): cache = TileCache(3, None) for key in range(3): cache[key] = str(key) assert set(cache) == {0, 1, 2} cache[3] = "3" assert set(cache) == {1, 2, 3}
def test_tilecache_can_constrain_bytes(): arr = np.ones((10, 10)) nbytes = arr.nbytes cache = TileCache(None, int(nbytes * 3.5)) for key in range(3): cache[key] = arr assert set(cache) == {0, 1, 2} cache[3] = arr assert set(cache) == {1, 2, 3}
def test_tilecache_can_get(): cache = TileCache(None, None) key = 1 value = 1 assert len(cache) == 0 cache[key] = value assert len(cache) == 1 response = cache[key] assert response == value
def test_tilecache_set_refreshes_old(): """Ensure that newly-pushed items get appended to the end, even if they already exist in the cache""" cache = TileCache(None, None) key = 1 value = 1 assert len(cache) == 0 cache[key] = value cache[2] = 2 assert list(cache) == [1, 2] cache[1] = 1 assert list(cache) == [2, 1]