mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +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
|
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
from test import support, list_tests
|
||||
import pickle
|
||||
|
||||
class ListTest(list_tests.CommonTest):
|
||||
type2test = list
|
||||
|
|
@ -69,6 +70,33 @@ class ListTest(list_tests.CommonTest):
|
|||
check(10) # check our checking code
|
||||
check(1000000)
|
||||
|
||||
def test_iterator_pickle(self):
|
||||
# Userlist iterators don't support pickling yet since
|
||||
# they are based on generators.
|
||||
data = self.type2test([4, 5, 6, 7])
|
||||
it = itorg = iter(data)
|
||||
d = pickle.dumps(it)
|
||||
it = pickle.loads(d)
|
||||
self.assertEqual(type(itorg), type(it))
|
||||
self.assertEqual(self.type2test(it), self.type2test(data))
|
||||
|
||||
it = pickle.loads(d)
|
||||
next(it)
|
||||
d = pickle.dumps(it)
|
||||
self.assertEqual(self.type2test(it), self.type2test(data)[1:])
|
||||
|
||||
def test_reversed_pickle(self):
|
||||
data = self.type2test([4, 5, 6, 7])
|
||||
it = itorg = reversed(data)
|
||||
d = pickle.dumps(it)
|
||||
it = pickle.loads(d)
|
||||
self.assertEqual(type(itorg), type(it))
|
||||
self.assertEqual(self.type2test(it), self.type2test(reversed(data)))
|
||||
|
||||
it = pickle.loads(d)
|
||||
next(it)
|
||||
d = pickle.dumps(it)
|
||||
self.assertEqual(self.type2test(it), self.type2test(reversed(data))[1:])
|
||||
|
||||
def test_main(verbose=None):
|
||||
support.run_unittest(ListTest)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue