[Python-checkins] cpython: Add more tests for pickling itertools.cycle

raymond.hettinger python-checkins at python.org
Sat Aug 15 23:46:16 CEST 2015


https://hg.python.org/cpython/rev/f6cc89b87ee3
changeset:   97393:f6cc89b87ee3
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Aug 15 14:45:49 2015 -0700
summary:
  Add more tests for pickling itertools.cycle

files:
  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
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -613,6 +613,23 @@
         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
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list