diff options
author | Raymond Hettinger <python@rcn.com> | 2015-08-15 21:45:49 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-08-15 21:45:49 (GMT) |
commit | a166ce561c8c80dc892deab491ff5625cc0409c8 (patch) | |
tree | 4d619199daeeb88a905c5ac90af8236bfa92d1ff /Lib/test/test_itertools.py | |
parent | 711dc147772b57137a71457b4005ee6d0bc2cada (diff) | |
download | cpython-a166ce561c8c80dc892deab491ff5625cc0409c8.zip cpython-a166ce561c8c80dc892deab491ff5625cc0409c8.tar.gz cpython-a166ce561c8c80dc892deab491ff5625cc0409c8.tar.bz2 |
Add more tests for pickling itertools.cycle
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r-- | Lib/test/test_itertools.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 53d6564..c012efd 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 |