mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Issue 7410: deepcopy of itertools.count resets the count
This commit is contained in:
parent
d46430bd81
commit
e09f45a2e3
2 changed files with 25 additions and 1 deletions
|
@ -7,6 +7,8 @@ from fractions import Fraction
|
|||
import sys
|
||||
import operator
|
||||
import random
|
||||
import copy
|
||||
import pickle
|
||||
maxsize = test_support.MAX_Py_ssize_t
|
||||
minsize = -maxsize-1
|
||||
|
||||
|
@ -346,6 +348,13 @@ class TestBasicOps(unittest.TestCase):
|
|||
r2 = 'count(%r)'.__mod__(i).replace('L', '')
|
||||
self.assertEqual(r1, r2)
|
||||
|
||||
# check copy, deepcopy, pickle
|
||||
for value in -3, 3, sys.maxint-5, sys.maxint+5:
|
||||
c = count(value)
|
||||
self.assertEqual(next(copy.copy(c)), value)
|
||||
self.assertEqual(next(copy.deepcopy(c)), value)
|
||||
self.assertEqual(next(pickle.loads(pickle.dumps(c))), value)
|
||||
|
||||
def test_count_with_stride(self):
|
||||
self.assertEqual(zip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
|
||||
self.assertEqual(zip('abc',count(start=2,step=3)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue