-
Notifications
You must be signed in to change notification settings - Fork 0
/
acdb_test.py
73 lines (54 loc) · 1.64 KB
/
acdb_test.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os.path
import tempfile
import pytest
import acdb
def driver_easy_case(driver):
driver.set('name', b'acdb')
assert driver.get('name') == b'acdb'
assert driver.all() == ['name']
driver.rm('name')
with pytest.raises(Exception):
driver.get('name')
def emerge_easy_test(emerge):
emerge.set('name', 'acdb')
assert emerge.get('name') == 'acdb'
assert emerge.all() == ['name']
emerge.rm('name')
emerge.set('n', 0)
for _ in range(64):
emerge.incr('n')
assert emerge.get('n') == 64
emerge.rm('n')
assert emerge.none('name')
emerge.set_none('name', 'acdb')
assert emerge.some('name')
emerge.set_some('name', 'bcad')
assert emerge.get('name') == 'bcad'
emerge.set_none('name', 'acdb')
assert emerge.get('name') == 'bcad'
def test_mem_driver():
driver = acdb.MemDriver()
driver_easy_case(driver)
def test_doc_driver():
driver = acdb.DocDriver(os.path.join(tempfile.gettempdir(), 'acdb'))
driver_easy_case(driver)
def test_lru_driver():
driver = acdb.LruDriver()
driver_easy_case(driver)
def test_lru_dirver_full():
driver = acdb.LruDriver(1024)
for i in range(1024):
driver.set(i, str(i))
assert len(driver.dict) == 1024
assert list(driver.dict.keys())[-1] == 1023
driver.set(1024, '1024')
assert len(driver.dict) == 769
assert driver.get(512) == '512'
with pytest.raises(KeyError):
driver.get(0)
def test_map_driver():
driver = acdb.MapDriver(os.path.join(tempfile.gettempdir(), 'acdb'))
driver_easy_case(driver)
def test_json_emerge():
emerge = acdb.mem()
emerge_easy_test(emerge)