@@ -70,14 +70,14 @@ def run_cached_keys(cache):
70
70
assert x == 30000
71
71
72
72
73
- def run_cached (cache ):
73
+ def run_cached (cache , key = ct . keys . hashkey ):
74
74
"""run something on a cached function."""
75
75
76
76
for cached in (ct .cached , ctu .cached ):
77
77
# reset cache contents and stats
78
78
reset_cache (cache )
79
79
# NOTE we probably trigger a double json encoding in some tests.
80
- fun = cached_fun (cache , cached , key = ctu . json_key )
80
+ fun = cached_fun (cache , cached , key = key )
81
81
x = 0
82
82
for n in range (10 ):
83
83
for i in range (5 ):
@@ -138,13 +138,13 @@ def test_key_ct():
138
138
run_cached (c1 )
139
139
run_cached (c2 )
140
140
assert len (c0 ) == 50
141
- assert 'f.[0,"a",false]' in c0
142
- assert c1 ['[3,"bb",true]' ] == 123
143
- assert 'f.[4,null,true]' in c0
144
- assert c2 ['[4," ccc",true]' ] == 134
141
+ assert "f.(0, 'a', False)" in c0
142
+ assert c1 ["(3, 'bb', True)" ] == 123
143
+ assert "f.(4, None, True)" in c0
144
+ assert c2 ["(4, ' ccc', True)" ] == 134
145
145
run_cached (c3 )
146
146
assert len (c0 ) == 100
147
- assert c3 ['[2,"",true]' ] == 102
147
+ assert c3 ["(2, '', True)" ] == 102
148
148
c0 .clear ()
149
149
setgetdel (c0 )
150
150
setgetdel (c1 )
@@ -163,7 +163,7 @@ def test_key_ct():
163
163
def test_stats_ct ():
164
164
c0 = ct .TTLCache (maxsize = 100 , ttl = 100 )
165
165
cache = ctu .StatsCache (c0 )
166
- run_cached (cache )
166
+ run_cached (cache , key = ctu . json_key )
167
167
assert len (cache ) == 50
168
168
# NOTE keys are jsonified in run_cached
169
169
assert cache ['[4,"a",true]' ] == 114
@@ -194,8 +194,8 @@ def test_memcached():
194
194
c1 = ctu .MemCached (c0 )
195
195
run_cached (c1 )
196
196
assert len (c1 ) >= 50
197
- assert c1 ['[1,"a",true]' ] == 111
198
- assert c1 ['[3,null,false]' ] == - 17
197
+ assert c1 ["(1, 'a', True)" ] == 111
198
+ assert c1 ["(3, None, False)" ] == - 17
199
199
assert isinstance (c1 .stats (), dict )
200
200
201
201
@@ -208,7 +208,7 @@ def test_key_memcached():
208
208
209
209
c0 = pmc .Client (server = "localhost" , serde = ctu .JsonSerde ())
210
210
c1 = ctu .PrefixedMemCached (c0 , "CacheToolsUtils." )
211
- run_cached (c1 )
211
+ run_cached (c1 , key = ctu . json_key )
212
212
assert len (c1 ) >= 50
213
213
assert c1 ['[1,"a",true]' ] == 111
214
214
assert c1 ['[3,null,false]' ] == - 17
@@ -223,7 +223,7 @@ def test_stats_memcached():
223
223
224
224
c0 = pmc .Client (server = "localhost" , serde = ctu .JsonSerde (), key_prefix = b"ctu." )
225
225
c1 = ctu .MemCached (c0 )
226
- run_cached (c1 )
226
+ run_cached (c1 , key = ctu . json_key )
227
227
assert len (c1 ) >= 50
228
228
assert c1 ['[1,"a",true]' ] == 111
229
229
assert c1 ['[3,null,false]' ] == - 17
@@ -251,8 +251,8 @@ def test_redis():
251
251
cache = ctu .LockedCache (c5 , threading .RLock ())
252
252
run_cached (cache )
253
253
assert len (cache ) >= 50
254
- assert cache ['[1,"a",true]' ] == 111
255
- assert cache ['[3,null,false]' ] == - 17
254
+ assert cache [( 1 , 'a' , True ) ] == 111
255
+ assert cache [( 3 , None , False ) ] == - 17
256
256
setgetdel (cache )
257
257
try :
258
258
cache .__iter__ ()
0 commit comments