summaryrefslogtreecommitdiff
path: root/Lib/test/test_range.py
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2012-04-03 10:49:41 +0000
committerKristján Valur Jónsson <kristjan@ccpgames.com>2012-04-03 10:49:41 +0000
commit31668b8f7a3efc7b17511bb08525b28e8ff5f23a (patch)
treeacc8d778b0135e0f345e94c3334d7c1eeb1dca0a /Lib/test/test_range.py
parent283b96b6bd974179b7f7f93f1c4631c3cc20c96d (diff)
downloadcpython-git-31668b8f7a3efc7b17511bb08525b28e8ff5f23a.tar.gz
Issue #14288: Serialization support for builtin iterators.
Diffstat (limited to 'Lib/test/test_range.py')
-rw-r--r--Lib/test/test_range.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py
index 2e335cc70d..f18046dde8 100644
--- a/Lib/test/test_range.py
+++ b/Lib/test/test_range.py
@@ -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