Esempio n. 1
0
def test_remove(cache):
    '''Remove item from cache.'''
    cache.set('key', 'value')
    cache.remove('key')

    with pytest.raises(KeyError):
        cache.get('key')
Esempio n. 2
0
def test_set(cache):
    '''Set item in cache.'''
    with pytest.raises(KeyError):
        cache.get('key')

    cache.set('key', 'value')
    assert cache.get('key') == 'value'
Esempio n. 3
0
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'])
Esempio n. 4
0
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']
Esempio n. 5
0
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()
Esempio n. 6
0
def test_get(cache):
    '''Retrieve item from cache.'''
    cache.set('key', 'value')
    assert cache.get('key') == 'value'