@@ -250,3 +250,52 @@ async def test_getsetdel(self, value):
250250 assert await self .cache .adelete (key )
251251 assert len (self .origin_cache ) == 0
252252 assert (await self .cache .aget (key )).default
253+
254+ async def test_clear (self ):
255+ for key in range (10 ):
256+ assert await self .cache .aset (key , key )
257+ assert len (self .origin_cache ) == 10
258+ await self .cache .aclear ()
259+ assert len (self .origin_cache ) == 0
260+
261+ async def test_stats (self , uid ):
262+ self .origin_cache .update_settings (statistics = True )
263+
264+ stats = await self .cache .astats ()
265+ assert stats .hits == 0
266+ assert stats .misses == 0
267+ assert stats == (0 , 0 )
268+
269+ assert len (self .origin_cache ) == 0
270+ await self .cache .aget (uid )
271+ assert (await self .cache .astats ()) == (0 , 1 )
272+ await self .cache .aget (uid )
273+ assert (await self .cache .astats ()) == (0 , 2 )
274+
275+ assert await self .cache .aset (uid , 0 )
276+ await self .cache .aget (uid )
277+ assert (await self .cache .astats ()) == (1 , 2 )
278+ await self .cache .aget (uid )
279+ assert (await self .cache .astats ()) == (2 , 2 )
280+
281+ @pytest .mark .parametrize ("enable" , [True , False ])
282+ async def test_stats_enable (self , uid , enable ):
283+ await self .cache .aget (uid )
284+ assert await self .cache .astats (enable = enable ) == (0 , 0 )
285+ await self .cache .aget (uid )
286+ assert await self .cache .aset (uid , 0 )
287+ await self .cache .aget (uid )
288+ assert await self .cache .astats () == (int (enable ), int (enable ))
289+
290+ @pytest .mark .parametrize ("reset" , [True , False ])
291+ async def test_stats_reset (self , uid , reset ):
292+ self .origin_cache .update_settings (statistics = True )
293+
294+ await self .cache .aget (uid )
295+ assert await self .cache .aset (uid , 0 )
296+ await self .cache .aget (uid )
297+ assert await self .cache .astats (reset = reset ) == (1 , 1 )
298+ assert await self .cache .astats () == (int (not reset ), int (not reset ))
299+
300+ # TODO: test_volume
301+ # TODO: test_close
0 commit comments