@@ -634,6 +634,7 @@ def test_cycle(self):
634634 self .assertRaises (TypeError , cycle , 5 )
635635 self .assertEqual (list (islice (cycle (gen3 ()),10 )), [0 ,1 ,2 ,0 ,1 ,2 ,0 ,1 ,2 ,0 ])
636636
637+ def test_cycle_copy_pickle (self ):
637638 # check copy, deepcopy, pickle
638639 c = cycle ('abc' )
639640 self .assertEqual (next (c ), 'a' )
@@ -669,6 +670,37 @@ def test_cycle(self):
669670 d = pickle .loads (p ) # rebuild the cycle object
670671 self .assertEqual (take (20 , d ), list ('cdeabcdeabcdeabcdeab' ))
671672
673+ def test_cycle_unpickle_compat (self ):
674+ testcases = [
675+ b'citertools\n cycle\n (c__builtin__\n iter\n ((lI1\n aI2\n aI3\n atRI1\n btR((lI1\n aI0\n tb.' ,
676+ b'citertools\n cycle\n (c__builtin__\n iter\n (](K\x01 K\x02 K\x03 etRK\x01 btR(]K\x01 aK\x00 tb.' ,
677+ b'\x80 \x02 citertools\n cycle\n c__builtin__\n iter\n ](K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 R]K\x01 aK\x00 \x86 b.' ,
678+ b'\x80 \x03 citertools\n cycle\n cbuiltins\n iter\n ](K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 R]K\x01 aK\x00 \x86 b.' ,
679+ b'\x80 \x04 \x95 =\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \t itertools\x8c \x05 cycle\x93 \x8c \x08 builtins\x8c \x04 iter\x93 ](K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 R]K\x01 aK\x00 \x86 b.' ,
680+
681+ b'citertools\n cycle\n (c__builtin__\n iter\n ((lp0\n I1\n aI2\n aI3\n atRI1\n btR(g0\n I1\n tb.' ,
682+ b'citertools\n cycle\n (c__builtin__\n iter\n (]q\x00 (K\x01 K\x02 K\x03 etRK\x01 btR(h\x00 K\x01 tb.' ,
683+ b'\x80 \x02 citertools\n cycle\n c__builtin__\n iter\n ]q\x00 (K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 Rh\x00 K\x01 \x86 b.' ,
684+ b'\x80 \x03 citertools\n cycle\n cbuiltins\n iter\n ]q\x00 (K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 Rh\x00 K\x01 \x86 b.' ,
685+ b'\x80 \x04 \x95 <\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \t itertools\x8c \x05 cycle\x93 \x8c \x08 builtins\x8c \x04 iter\x93 ]\x94 (K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 Rh\x00 K\x01 \x86 b.' ,
686+
687+ b'citertools\n cycle\n (c__builtin__\n iter\n ((lI1\n aI2\n aI3\n atRI1\n btR((lI1\n aI00\n tb.' ,
688+ b'citertools\n cycle\n (c__builtin__\n iter\n (](K\x01 K\x02 K\x03 etRK\x01 btR(]K\x01 aI00\n tb.' ,
689+ b'\x80 \x02 citertools\n cycle\n c__builtin__\n iter\n ](K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 R]K\x01 a\x89 \x86 b.' ,
690+ b'\x80 \x03 citertools\n cycle\n cbuiltins\n iter\n ](K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 R]K\x01 a\x89 \x86 b.' ,
691+ b'\x80 \x04 \x95 <\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \t itertools\x8c \x05 cycle\x93 \x8c \x08 builtins\x8c \x04 iter\x93 ](K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 R]K\x01 a\x89 \x86 b.' ,
692+
693+ b'citertools\n cycle\n (c__builtin__\n iter\n ((lp0\n I1\n aI2\n aI3\n atRI1\n btR(g0\n I01\n tb.' ,
694+ b'citertools\n cycle\n (c__builtin__\n iter\n (]q\x00 (K\x01 K\x02 K\x03 etRK\x01 btR(h\x00 I01\n tb.' ,
695+ b'\x80 \x02 citertools\n cycle\n c__builtin__\n iter\n ]q\x00 (K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 Rh\x00 \x88 \x86 b.' ,
696+ b'\x80 \x03 citertools\n cycle\n cbuiltins\n iter\n ]q\x00 (K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 Rh\x00 \x88 \x86 b.' ,
697+ b'\x80 \x04 \x95 ;\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x8c \t itertools\x8c \x05 cycle\x93 \x8c \x08 builtins\x8c \x04 iter\x93 ]\x94 (K\x01 K\x02 K\x03 e\x85 RK\x01 b\x85 Rh\x00 \x88 \x86 b.' ,
698+ ]
699+ assert len (testcases ) == 20
700+ for t in testcases :
701+ it = pickle .loads (t )
702+ self .assertEqual (take (10 , it ), [2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 ])
703+
672704 def test_cycle_setstate (self ):
673705 # Verify both modes for restoring state
674706
0 commit comments