@@ -650,10 +650,23 @@ def func(key, *args):
650
650
old_func = cache .key_func
651
651
cache .key_func = func
652
652
653
+ tests = [
654
+ ('add' , [key , 1 ]),
655
+ ('get' , [key ]),
656
+ ('set' , [key , 1 ]),
657
+ ('incr' , [key ]),
658
+ ('decr' , [key ]),
659
+ ('delete' , [key ]),
660
+ ('get_many' , [[key , 'b' ]]),
661
+ ('set_many' , [{key : 1 , 'b' : 2 }]),
662
+ ('delete_many' , [{key : 1 , 'b' : 2 }]),
663
+ ]
653
664
try :
654
- with self .assertWarns (CacheKeyWarning ) as cm :
655
- cache .set (key , 'value' )
656
- self .assertEqual (str (cm .warning ), expected_warning )
665
+ for operation , args in tests :
666
+ with self .subTest (operation = operation ):
667
+ with self .assertWarns (CacheKeyWarning ) as cm :
668
+ getattr (cache , operation )(* args )
669
+ self .assertEqual (str (cm .warning ), expected_warning )
657
670
finally :
658
671
cache .key_func = old_func
659
672
@@ -1291,9 +1304,19 @@ def _perform_invalid_key_test(self, key, expected_warning):
1291
1304
key.
1292
1305
"""
1293
1306
msg = expected_warning .replace (key , cache .make_key (key ))
1294
- with self .assertRaises (InvalidCacheKey ) as cm :
1295
- cache .set (key , 'value' )
1296
- self .assertEqual (str (cm .exception ), msg )
1307
+ tests = [
1308
+ ('add' , [key , 1 ]),
1309
+ ('set' , [key , 1 ]),
1310
+ ('incr' , [key ]),
1311
+ ('decr' , [key ]),
1312
+ ('get_many' , [[key , 'b' ]]),
1313
+ ('set_many' , [{key : 1 , 'b' : 2 }]),
1314
+ ]
1315
+ for operation , args in tests :
1316
+ with self .subTest (operation = operation ):
1317
+ with self .assertRaises (InvalidCacheKey ) as cm :
1318
+ getattr (cache , operation )(* args )
1319
+ self .assertEqual (str (cm .exception ), msg )
1297
1320
1298
1321
def test_default_never_expiring_timeout (self ):
1299
1322
# Regression test for #22845
0 commit comments