From: Raymond Hettinger Date: Sat, 15 Aug 2015 21:45:49 +0000 (-0700) Subject: Add more tests for pickling itertools.cycle X-Git-Tag: v3.6.0a1~1785 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a166ce561c8c80dc892deab491ff5625cc0409c8;p=python Add more tests for pickling itertools.cycle --- diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 53d65649ff..c012efd752 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -613,6 +613,23 @@ class TestBasicOps(unittest.TestCase): for proto in range(pickle.HIGHEST_PROTOCOL + 1): self.pickletest(proto, cycle('abc')) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + # test with partial consumed input iterable + it = iter('abcde') + c = cycle(it) + _ = [next(c) for i in range(2)] # consume to 2 of 5 inputs + p = pickle.dumps(c, proto) + d = pickle.loads(p) # rebuild the cycle object + self.assertEqual(take(20, d), list('cdeabcdeabcdeabcdeab')) + + # test with completely consumed input iterable + it = iter('abcde') + c = cycle(it) + _ = [next(c) for i in range(7)] # consume to 7 of 5 inputs + p = pickle.dumps(c, proto) + d = pickle.loads(p) # rebuild the cycle object + self.assertEqual(take(20, d), list('cdeabcdeabcdeabcdeab')) + def test_cycle_setstate(self): # Verify both modes for restoring state