15
15
import struct
16
16
import threading
17
17
import gc
18
+ import warnings
19
+
20
+ def pickle_deprecated (testfunc ):
21
+ """ Run the test three times.
22
+ First, verify that a Deprecation Warning is raised.
23
+ Second, run normally but with DeprecationWarnings temporarily disabled.
24
+ Third, run with warnings promoted to errors.
25
+ """
26
+ def inner (self ):
27
+ with self .assertWarns (DeprecationWarning ):
28
+ testfunc (self )
29
+ with warnings .catch_warnings ():
30
+ warnings .simplefilter ("ignore" , category = DeprecationWarning )
31
+ testfunc (self )
32
+ with warnings .catch_warnings ():
33
+ warnings .simplefilter ("error" , category = DeprecationWarning )
34
+ with self .assertRaises ((DeprecationWarning , AssertionError , SystemError )):
35
+ testfunc (self )
36
+
37
+ return inner
18
38
19
39
maxsize = support .MAX_Py_ssize_t
20
40
minsize = - maxsize - 1
@@ -124,6 +144,7 @@ def expand(it, i=0):
124
144
c = expand (compare [took :])
125
145
self .assertEqual (a , c );
126
146
147
+ @pickle_deprecated
127
148
def test_accumulate (self ):
128
149
self .assertEqual (list (accumulate (range (10 ))), # one positional arg
129
150
[0 , 1 , 3 , 6 , 10 , 15 , 21 , 28 , 36 , 45 ])
@@ -220,6 +241,7 @@ def test_chain_from_iterable(self):
220
241
self .assertRaises (TypeError , list , chain .from_iterable ([2 , 3 ]))
221
242
self .assertEqual (list (islice (chain .from_iterable (repeat (range (5 ))), 2 )), [0 , 1 ])
222
243
244
+ @pickle_deprecated
223
245
def test_chain_reducible (self ):
224
246
for oper in [copy .deepcopy ] + picklecopiers :
225
247
it = chain ('abc' , 'def' )
@@ -233,6 +255,7 @@ def test_chain_reducible(self):
233
255
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
234
256
self .pickletest (proto , chain ('abc' , 'def' ), compare = list ('abcdef' ))
235
257
258
+ @pickle_deprecated
236
259
def test_chain_setstate (self ):
237
260
self .assertRaises (TypeError , chain ().__setstate__ , ())
238
261
self .assertRaises (TypeError , chain ().__setstate__ , [])
@@ -246,6 +269,7 @@ def test_chain_setstate(self):
246
269
it .__setstate__ ((iter (['abc' , 'def' ]), iter (['ghi' ])))
247
270
self .assertEqual (list (it ), ['ghi' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ])
248
271
272
+ @pickle_deprecated
249
273
def test_combinations (self ):
250
274
self .assertRaises (TypeError , combinations , 'abc' ) # missing r argument
251
275
self .assertRaises (TypeError , combinations , 'abc' , 2 , 1 ) # too many arguments
@@ -269,7 +293,6 @@ def test_combinations(self):
269
293
self .assertEqual (list (op (testIntermediate )),
270
294
[(0 ,1 ,3 ), (0 ,2 ,3 ), (1 ,2 ,3 )])
271
295
272
-
273
296
def combinations1 (iterable , r ):
274
297
'Pure python version shown in the docs'
275
298
pool = tuple (iterable )
@@ -337,6 +360,7 @@ def test_combinations_tuple_reuse(self):
337
360
self .assertEqual (len (set (map (id , combinations ('abcde' , 3 )))), 1 )
338
361
self .assertNotEqual (len (set (map (id , list (combinations ('abcde' , 3 ))))), 1 )
339
362
363
+ @pickle_deprecated
340
364
def test_combinations_with_replacement (self ):
341
365
cwr = combinations_with_replacement
342
366
self .assertRaises (TypeError , cwr , 'abc' ) # missing r argument
@@ -425,6 +449,7 @@ def test_combinations_with_replacement_tuple_reuse(self):
425
449
self .assertEqual (len (set (map (id , cwr ('abcde' , 3 )))), 1 )
426
450
self .assertNotEqual (len (set (map (id , list (cwr ('abcde' , 3 ))))), 1 )
427
451
452
+ @pickle_deprecated
428
453
def test_permutations (self ):
429
454
self .assertRaises (TypeError , permutations ) # too few arguments
430
455
self .assertRaises (TypeError , permutations , 'abc' , 2 , 1 ) # too many arguments
@@ -531,6 +556,7 @@ def test_combinatorics(self):
531
556
self .assertEqual (comb , list (filter (set (perm ).__contains__ , cwr ))) # comb: cwr that is a perm
532
557
self .assertEqual (comb , sorted (set (cwr ) & set (perm ))) # comb: both a cwr and a perm
533
558
559
+ @pickle_deprecated
534
560
def test_compress (self ):
535
561
self .assertEqual (list (compress (data = 'ABCDEF' , selectors = [1 ,0 ,1 ,0 ,1 ,1 ])), list ('ACEF' ))
536
562
self .assertEqual (list (compress ('ABCDEF' , [1 ,0 ,1 ,0 ,1 ,1 ])), list ('ACEF' ))
@@ -564,7 +590,7 @@ def test_compress(self):
564
590
next (testIntermediate )
565
591
self .assertEqual (list (op (testIntermediate )), list (result2 ))
566
592
567
-
593
+ @ pickle_deprecated
568
594
def test_count (self ):
569
595
self .assertEqual (lzip ('abc' ,count ()), [('a' , 0 ), ('b' , 1 ), ('c' , 2 )])
570
596
self .assertEqual (lzip ('abc' ,count (3 )), [('a' , 3 ), ('b' , 4 ), ('c' , 5 )])
@@ -613,6 +639,7 @@ def test_count(self):
613
639
#check proper internal error handling for large "step' sizes
614
640
count (1 , maxsize + 5 ); sys .exc_info ()
615
641
642
+ @pickle_deprecated
616
643
def test_count_with_stride (self ):
617
644
self .assertEqual (lzip ('abc' ,count (2 ,3 )), [('a' , 2 ), ('b' , 5 ), ('c' , 8 )])
618
645
self .assertEqual (lzip ('abc' ,count (start = 2 ,step = 3 )),
@@ -675,6 +702,7 @@ def test_cycle(self):
675
702
self .assertRaises (TypeError , cycle , 5 )
676
703
self .assertEqual (list (islice (cycle (gen3 ()),10 )), [0 ,1 ,2 ,0 ,1 ,2 ,0 ,1 ,2 ,0 ])
677
704
705
+ @pickle_deprecated
678
706
def test_cycle_copy_pickle (self ):
679
707
# check copy, deepcopy, pickle
680
708
c = cycle ('abc' )
@@ -711,6 +739,7 @@ def test_cycle_copy_pickle(self):
711
739
d = pickle .loads (p ) # rebuild the cycle object
712
740
self .assertEqual (take (20 , d ), list ('cdeabcdeabcdeabcdeab' ))
713
741
742
+ @pickle_deprecated
714
743
def test_cycle_unpickle_compat (self ):
715
744
testcases = [
716
745
b'citertools\n cycle\n (c__builtin__\n iter\n ((lI1\n aI2\n aI3\n atRI1\n btR((lI1\n aI0\n tb.' ,
@@ -742,6 +771,7 @@ def test_cycle_unpickle_compat(self):
742
771
it = pickle .loads (t )
743
772
self .assertEqual (take (10 , it ), [2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 ])
744
773
774
+ @pickle_deprecated
745
775
def test_cycle_setstate (self ):
746
776
# Verify both modes for restoring state
747
777
@@ -778,6 +808,7 @@ def test_cycle_setstate(self):
778
808
self .assertRaises (TypeError , cycle ('' ).__setstate__ , ())
779
809
self .assertRaises (TypeError , cycle ('' ).__setstate__ , ([],))
780
810
811
+ @pickle_deprecated
781
812
def test_groupby (self ):
782
813
# Check whether it accepts arguments correctly
783
814
self .assertEqual ([], list (groupby ([])))
@@ -935,6 +966,7 @@ def test_filter(self):
935
966
c = filter (isEven , range (6 ))
936
967
self .pickletest (proto , c )
937
968
969
+ @pickle_deprecated
938
970
def test_filterfalse (self ):
939
971
self .assertEqual (list (filterfalse (isEven , range (6 ))), [1 ,3 ,5 ])
940
972
self .assertEqual (list (filterfalse (None , [0 ,1 ,0 ,2 ,0 ])), [0 ,0 ,0 ])
@@ -965,6 +997,7 @@ def test_zip(self):
965
997
lzip ('abc' , 'def' ))
966
998
967
999
@support .impl_detail ("tuple reuse is specific to CPython" )
1000
+ @pickle_deprecated
968
1001
def test_zip_tuple_reuse (self ):
969
1002
ids = list (map (id , zip ('abc' , 'def' )))
970
1003
self .assertEqual (min (ids ), max (ids ))
@@ -1040,6 +1073,7 @@ def test_zip_longest_tuple_reuse(self):
1040
1073
ids = list (map (id , list (zip_longest ('abc' , 'def' ))))
1041
1074
self .assertEqual (len (dict .fromkeys (ids )), len (ids ))
1042
1075
1076
+ @pickle_deprecated
1043
1077
def test_zip_longest_pickling (self ):
1044
1078
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
1045
1079
self .pickletest (proto , zip_longest ("abc" , "def" ))
@@ -1186,6 +1220,7 @@ def test_product_tuple_reuse(self):
1186
1220
self .assertEqual (len (set (map (id , product ('abc' , 'def' )))), 1 )
1187
1221
self .assertNotEqual (len (set (map (id , list (product ('abc' , 'def' ))))), 1 )
1188
1222
1223
+ @pickle_deprecated
1189
1224
def test_product_pickling (self ):
1190
1225
# check copy, deepcopy, pickle
1191
1226
for args , result in [
@@ -1201,6 +1236,7 @@ def test_product_pickling(self):
1201
1236
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
1202
1237
self .pickletest (proto , product (* args ))
1203
1238
1239
+ @pickle_deprecated
1204
1240
def test_product_issue_25021 (self ):
1205
1241
# test that indices are properly clamped to the length of the tuples
1206
1242
p = product ((1 , 2 ),(3 ,))
@@ -1211,6 +1247,7 @@ def test_product_issue_25021(self):
1211
1247
p .__setstate__ ((0 , 0 , 0x1000 )) # will access tuple element 1 if not clamped
1212
1248
self .assertRaises (StopIteration , next , p )
1213
1249
1250
+ @pickle_deprecated
1214
1251
def test_repeat (self ):
1215
1252
self .assertEqual (list (repeat (object = 'a' , times = 3 )), ['a' , 'a' , 'a' ])
1216
1253
self .assertEqual (lzip (range (3 ),repeat ('a' )),
@@ -1243,6 +1280,7 @@ def test_repeat_with_negative_times(self):
1243
1280
self .assertEqual (repr (repeat ('a' , times = - 1 )), "repeat('a', 0)" )
1244
1281
self .assertEqual (repr (repeat ('a' , times = - 2 )), "repeat('a', 0)" )
1245
1282
1283
+ @pickle_deprecated
1246
1284
def test_map (self ):
1247
1285
self .assertEqual (list (map (operator .pow , range (3 ), range (1 ,7 ))),
1248
1286
[0 ** 1 , 1 ** 2 , 2 ** 3 ])
@@ -1273,6 +1311,7 @@ def test_map(self):
1273
1311
c = map (tupleize , 'abc' , count ())
1274
1312
self .pickletest (proto , c )
1275
1313
1314
+ @pickle_deprecated
1276
1315
def test_starmap (self ):
1277
1316
self .assertEqual (list (starmap (operator .pow , zip (range (3 ), range (1 ,7 )))),
1278
1317
[0 ** 1 , 1 ** 2 , 2 ** 3 ])
@@ -1300,6 +1339,7 @@ def test_starmap(self):
1300
1339
c = starmap (operator .pow , zip (range (3 ), range (1 ,7 )))
1301
1340
self .pickletest (proto , c )
1302
1341
1342
+ @pickle_deprecated
1303
1343
def test_islice (self ):
1304
1344
for args in [ # islice(args) should agree with range(args)
1305
1345
(10 , 20 , 3 ),
@@ -1394,6 +1434,7 @@ def __index__(self):
1394
1434
self .assertEqual (list (islice (range (100 ), IntLike (10 ), IntLike (50 ), IntLike (5 ))),
1395
1435
list (range (10 ,50 ,5 )))
1396
1436
1437
+ @pickle_deprecated
1397
1438
def test_takewhile (self ):
1398
1439
data = [1 , 3 , 5 , 20 , 2 , 4 , 6 , 8 ]
1399
1440
self .assertEqual (list (takewhile (underten , data )), [1 , 3 , 5 ])
@@ -1414,6 +1455,7 @@ def test_takewhile(self):
1414
1455
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
1415
1456
self .pickletest (proto , takewhile (underten , data ))
1416
1457
1458
+ @pickle_deprecated
1417
1459
def test_dropwhile (self ):
1418
1460
data = [1 , 3 , 5 , 20 , 2 , 4 , 6 , 8 ]
1419
1461
self .assertEqual (list (dropwhile (underten , data )), [20 , 2 , 4 , 6 , 8 ])
@@ -1431,6 +1473,7 @@ def test_dropwhile(self):
1431
1473
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
1432
1474
self .pickletest (proto , dropwhile (underten , data ))
1433
1475
1476
+ @pickle_deprecated
1434
1477
def test_tee (self ):
1435
1478
n = 200
1436
1479
@@ -1732,6 +1775,7 @@ class TestExamples(unittest.TestCase):
1732
1775
def test_accumulate (self ):
1733
1776
self .assertEqual (list (accumulate ([1 ,2 ,3 ,4 ,5 ])), [1 , 3 , 6 , 10 , 15 ])
1734
1777
1778
+ @pickle_deprecated
1735
1779
def test_accumulate_reducible (self ):
1736
1780
# check copy, deepcopy, pickle
1737
1781
data = [1 , 2 , 3 , 4 , 5 ]
@@ -1747,6 +1791,7 @@ def test_accumulate_reducible(self):
1747
1791
self .assertEqual (list (copy .deepcopy (it )), accumulated [1 :])
1748
1792
self .assertEqual (list (copy .copy (it )), accumulated [1 :])
1749
1793
1794
+ @pickle_deprecated
1750
1795
def test_accumulate_reducible_none (self ):
1751
1796
# Issue #25718: total is None
1752
1797
it = accumulate ([None , None , None ], operator .is_ )
0 commit comments