diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-06 12:12:04 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-06 12:12:04 (GMT) |
commit | de128e19e2c6186408692a37f563550df13a390c (patch) | |
tree | 30902cbc57725b33359163cee5bb30582cccf831 /Lib/test/test_deque.py | |
parent | 5608411a964f7fd5a35eda04b297e0d77de9958d (diff) | |
parent | aabafe7bc293b377629ff97c3e955956eaf6350a (diff) | |
download | cpython-de128e19e2c6186408692a37f563550df13a390c.zip cpython-de128e19e2c6186408692a37f563550df13a390c.tar.gz cpython-de128e19e2c6186408692a37f563550df13a390c.tar.bz2 |
Issue #26015: Added new tests for pickling iterators of mutable sequences.
Diffstat (limited to 'Lib/test/test_deque.py')
-rw-r--r-- | Lib/test/test_deque.py | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 634d71f..29b44f6 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -640,18 +640,45 @@ class TestBasic(unittest.TestCase): self.assertEqual(e.maxlen, d.maxlen) def test_iterator_pickle(self): - data = deque(range(200)) + orig = deque(range(200)) + data = [i*1.01 for i in orig] for proto in range(pickle.HIGHEST_PROTOCOL + 1): - it = itorg = iter(data) - d = pickle.dumps(it, proto) - it = pickle.loads(d) - self.assertEqual(type(itorg), type(it)) - self.assertEqual(list(it), list(data)) - - it = pickle.loads(d) - next(it) - d = pickle.dumps(it, proto) - self.assertEqual(list(it), list(data)[1:]) + # initial iterator + itorg = iter(orig) + dump = pickle.dumps((itorg, orig), proto) + it, d = pickle.loads(dump) + for i, x in enumerate(data): + d[i] = x + self.assertEqual(type(it), type(itorg)) + self.assertEqual(list(it), data) + + # running iterator + next(itorg) + dump = pickle.dumps((itorg, orig), proto) + it, d = pickle.loads(dump) + for i, x in enumerate(data): + d[i] = x + self.assertEqual(type(it), type(itorg)) + self.assertEqual(list(it), data[1:]) + + # empty iterator + for i in range(1, len(data)): + next(itorg) + dump = pickle.dumps((itorg, orig), proto) + it, d = pickle.loads(dump) + for i, x in enumerate(data): + d[i] = x + self.assertEqual(type(it), type(itorg)) + self.assertEqual(list(it), []) + + # exhausted iterator + self.assertRaises(StopIteration, next, itorg) + dump = pickle.dumps((itorg, orig), proto) + it, d = pickle.loads(dump) + for i, x in enumerate(data): + d[i] = x + self.assertEqual(type(it), type(itorg)) + self.assertEqual(list(it), []) def test_deepcopy(self): mut = [10] |