@@ -24,6 +24,15 @@ def get_new_cache(id_: str = None, *, clear=True, **kwargs) -> Cache:
24
24
return cache
25
25
26
26
27
+ def get_cache_with_items (* args , ** kwargs ) -> tuple [Cache , dict [int , str ]]:
28
+ cache = get_new_cache (* args , ** kwargs )
29
+
30
+ items = {i : str (i ) for i in range (16 )}
31
+
32
+ cache .set_many (items .items ())
33
+ return cache , items
34
+
35
+
27
36
def test_basic_cache (test_key , test_value ):
28
37
first = get_new_cache ()
29
38
first [test_key ] = test_value
@@ -142,4 +151,49 @@ def test_max_memory_usage():
142
151
assert end_max_memory_usage - starting_max_memory < 3_000
143
152
144
153
154
+ def test_equals ():
155
+ cache = get_new_cache ()
156
+ cache2 = get_new_cache (max_items = 64 )
157
+ assert cache == cache2
158
+
159
+ cache3 = get_new_cache ("Another" )
160
+ assert cache != cache3
161
+
162
+
163
+ def test_contains_many ():
164
+ cache , items = get_cache_with_items ()
165
+
166
+ keys = tuple (items .keys ())
167
+ in_keys , ins = zip (* cache .contains_many (keys ))
168
+
169
+ assert in_keys == keys
170
+ assert all (ins )
171
+
172
+
173
+ def test_get_many ():
174
+ cache , items = get_cache_with_items ()
175
+
176
+ keys = tuple (items .keys ())
177
+ in_keys , values = zip (* cache .get_many (keys ))
178
+
179
+ assert in_keys == keys
180
+ assert values == tuple (items .values ())
181
+
182
+
183
+ def test_set_many ():
184
+ cache , items = get_cache_with_items ()
185
+
186
+ for key , value in items .items ():
187
+ assert value == cache [key ]
188
+
189
+
190
+ def test_del_many ():
191
+ cache , items = get_cache_with_items ()
192
+
193
+ keys = tuple (items .keys ())
194
+ cache .del_many (keys )
195
+
196
+ assert len (cache ) == 0
197
+
198
+
145
199
# TODO: Add parallel test for cache as well (threading)
0 commit comments