-
Notifications
You must be signed in to change notification settings - Fork 125
/
tests.py
117 lines (95 loc) · 3.15 KB
/
tests.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from __future__ import print_function
import pickledb
# a work in progress
class TestClass(object):
db = pickledb.load('tests.db', auto_dump=False)
def test_load(self):
x = pickledb.load('x.db', auto_dump=False)
assert x is not None
def test_sugar_get(self):
self.db.db["foo"] = "bar"
x = self.db["foo"]
assert x == "bar"
def test_sugar_set(self):
self.db["foo"] = "bar"
assert "bar" == self.db.db["foo"]
def test_sugar_rem(self):
self.db.db["foo"] = "bar"
del self.db["foo"]
assert "foo" not in self.db.db
def test_set(self):
self.db.set('key', 'value')
x = self.db.get('key')
assert x == 'value'
def test_getall(self):
self.db.deldb()
self.db.set('key1', 'value1')
self.db.set('key2', 'value2')
self.db.dcreate('dict1')
self.db.lcreate('list1')
x = self.db.getall()
y = dict.fromkeys(['key2', 'key1', 'dict1', 'list1']).keys()
assert x == y
def test_get(self):
self.db.set('key', 'value')
x = self.db.get('key')
assert x == 'value'
def test_rem(self):
self.db.set('key', 'value')
self.db.rem('key')
x = self.db.get('key')
assert x is False
def test_append(self):
self.db.set('key', 'value')
self.db.append('key', 'value')
x = self.db.get('key')
assert x == 'valuevalue'
def test_exists(self):
self.db.set('key', 'value')
x = self.db.exists('key')
assert x is True
self.db.rem('key')
def test_not_exists(self):
self.db.set('key', 'value')
x = self.db.exists('not_key')
assert x is False
self.db.rem('key')
def test_lexists(self):
self.db.lcreate('list')
self.db.ladd('list', 'value')
x = self.db.lexists('list', 'value')
assert x is True
self.db.lremlist('list')
def test_not_lexists(self):
self.db.lcreate('list')
self.db.ladd('list', 'value')
x = self.db.lexists('list', 'not_value')
assert x is False
self.db.lremlist('list')
def test_lrange(self):
self.db.lcreate('list')
self.db.ladd('list','one')
self.db.ladd('list','two')
self.db.ladd('list','three')
self.db.ladd('list','four')
x = self.db.lrange('list', 1, 3)
assert x == ['two', 'three']
self.db.lremlist('list')
def test_dexists(self):
self.db.dcreate('dict')
self.db.dadd('dict', ('key', 'value'))
x = self.db.dexists('dict', 'key')
assert x is True
self.db.drem('dict')
def test_not_dexists(self):
self.db.dcreate('dict')
self.db.dadd('dict', ('key', 'value'))
x = self.db.dexists('dict', 'not_key')
assert x is False
self.db.drem('dict')
if __name__ == "__main__":
tests = TestClass()
test_methods = [method for method in dir(tests) if callable(getattr(tests, method)) if method.startswith('test_')]
for method in test_methods:
getattr(tests, method)() # run method
print(".", end="")