Example #1
0
def test_remove(Cache, obj1, obj2, obj3):
    cache = Cache(5)
    cache.add(obj1)
    cache.add(obj2)
    cache.add(obj3)
    cache.remove(obj2)
    assert sorted(cache.get_cached()) == [obj1, obj3]
Example #2
0
def test_clear(Cache, obj_infos):
    """The clear method empties the cache."""
    cache = Cache(5)
    for obj_info in obj_infos:
        cache.add(obj_info)
    cache.clear()
    assert cache.get_cached() == []

    # Just an additional check ensuring that any additional structures
    # which may be used were cleaned properly as well.
    for obj_info in obj_infos:
        assert not cache.remove(obj_info)
Example #3
0
def test_remove_with_size_zero(Cache, obj1):
    """Cache is disabled entirely on remove() if size is 0."""
    cache = Cache(0)
    cache.remove(obj1)