mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #14288: Serialization support for builtin iterators.
This commit is contained in:
parent
283b96b6bd
commit
31668b8f7a
28 changed files with 2190 additions and 104 deletions
|
@ -341,13 +341,35 @@ class RangeTest(unittest.TestCase):
|
|||
|
||||
def test_pickling(self):
|
||||
testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1),
|
||||
(13, 21, 3), (-2, 2, 2)]
|
||||
(13, 21, 3), (-2, 2, 2), (2**65, 2**65+2)]
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
for t in testcases:
|
||||
r = range(*t)
|
||||
self.assertEqual(list(pickle.loads(pickle.dumps(r, proto))),
|
||||
list(r))
|
||||
|
||||
def test_iterator_pickling(self):
|
||||
testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1),
|
||||
(13, 21, 3), (-2, 2, 2), (2**65, 2**65+2)]
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
for t in testcases:
|
||||
it = itorg = iter(range(*t))
|
||||
data = list(range(*t))
|
||||
|
||||
d = pickle.dumps(it)
|
||||
it = pickle.loads(d)
|
||||
self.assertEqual(type(itorg), type(it))
|
||||
self.assertEqual(list(it), data)
|
||||
|
||||
it = pickle.loads(d)
|
||||
try:
|
||||
next(it)
|
||||
except StopIteration:
|
||||
continue
|
||||
d = pickle.dumps(it)
|
||||
it = pickle.loads(d)
|
||||
self.assertEqual(list(it), data[1:])
|
||||
|
||||
def test_odd_bug(self):
|
||||
# This used to raise a "SystemError: NULL result without error"
|
||||
# because the range validation step was eating the exception
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue