예제 #1
0
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
예제 #2
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]
예제 #3
0
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}
예제 #4
0
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}
예제 #5
0
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
예제 #6
0
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]