mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Add more tests for pickling itertools.cycle
This commit is contained in:
parent
711dc14777
commit
a166ce561c
1 changed files with 17 additions and 0 deletions
|
@ -613,6 +613,23 @@ class TestBasicOps(unittest.TestCase):
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
self.pickletest(proto, cycle('abc'))
|
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):
|
def test_cycle_setstate(self):
|
||||||
# Verify both modes for restoring state
|
# Verify both modes for restoring state
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue