def test_remove(cache): '''Remove item from cache.''' cache.set('key', 'value') cache.remove('key') with pytest.raises(KeyError): cache.get('key')
def test_set(cache): '''Set item in cache.''' with pytest.raises(KeyError): cache.get('key') cache.set('key', 'value') assert cache.get('key') == 'value'
def test_keys(cache): '''Retrieve keys of items in cache.''' assert cache.keys() == [] cache.set('a', 'a_value') cache.set('b', 'b_value') cache.set('c', 'c_value') assert sorted(cache.keys()) == sorted(['a', 'b', 'c'])
def test_clear_using_pattern(cache): '''Remove items that match pattern from cache.''' cache.set('matching_key', 'value') cache.set('another_matching_key', 'value') cache.set('key_not_matching', 'value') assert cache.keys() cache.clear(pattern='.*matching_key$') assert cache.keys() == ['key_not_matching']
def test_clear(cache): '''Remove items from cache.''' cache.set('a', 'a_value') cache.set('b', 'b_value') cache.set('c', 'c_value') assert cache.keys() cache.clear() assert not cache.keys()
def test_get(cache): '''Retrieve item from cache.''' cache.set('key', 'value') assert cache.get('key') == 'value'