forked from lyft/python-blessclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbless_cache_test.py
More file actions
44 lines (32 loc) · 1.19 KB
/
Copy pathbless_cache_test.py
File metadata and controls
44 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from blessclient.bless_cache import BlessCache
def test_get():
bc = BlessCache(None, None, BlessCache.CACHEMODE_ENABLED)
bc.cache = {'foo': 'bar'}
assert bc.get('foo') == 'bar'
assert bc.get('DOESNOTEXIST') is None
def test_get_nocache():
bc = BlessCache(None, None, BlessCache.CACHEMODE_DISABLED)
bc.cache = {'foo': 'bar'}
assert bc.get('foo') is None
def test_set():
bc = BlessCache(None, None, BlessCache.CACHEMODE_DISABLED)
bc.cache = {}
bc.set('foo', 'bar')
assert bc.cache == {'foo': 'bar'}
assert bc.dirty == True
def test_save_cache(tmpdir):
bc = BlessCache(str(tmpdir), 'cache', BlessCache.CACHEMODE_ENABLED)
bc.cache = {'foo': 'bar'}
bc.dirty = True
bc.save()
assert len(tmpdir.listdir()) == 1
def test_load_cache(tmpdir):
tmpdir.join('readcache').write('{"foo": "bar"}')
bc = BlessCache(str(tmpdir), 'readcache', BlessCache.CACHEMODE_ENABLED)
bar = bc.get('foo')
assert bar == 'bar'
def test_load_cache(tmpdir):
tmpdir.join('readcache_corrupted').write('{"foo": "bar"}}}')
bc = BlessCache(str(tmpdir), 'readcache_corrupted', BlessCache.CACHEMODE_ENABLED)
bar = bc.get('foo')
assert bar == None