mirror of https://github.com/python/cpython.git
Issue #26492: Added additional tests for exhausted iterators of mutable sequences.
This commit is contained in:
commit
f39c0ac62f
|
@ -593,3 +593,14 @@ class F(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
raise KeyboardInterrupt
|
raise KeyboardInterrupt
|
||||||
self.assertRaises(KeyboardInterrupt, list, F())
|
self.assertRaises(KeyboardInterrupt, list, F())
|
||||||
|
|
||||||
|
def test_exhausted_iterator(self):
|
||||||
|
a = self.type2test([1, 2, 3])
|
||||||
|
exhit = iter(a)
|
||||||
|
empit = iter(a)
|
||||||
|
for x in exhit: # exhaust the iterator
|
||||||
|
next(empit) # not exhausted
|
||||||
|
a.append(9)
|
||||||
|
self.assertEqual(list(exhit), [])
|
||||||
|
self.assertEqual(list(empit), [9])
|
||||||
|
self.assertEqual(a, self.type2test([1, 2, 3, 9]))
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
import test.support
|
import test.support
|
||||||
import test.string_tests
|
import test.string_tests
|
||||||
import test.buffer_tests
|
import test.buffer_tests
|
||||||
|
import test.list_tests
|
||||||
from test.support import bigaddrspacetest, MAX_Py_ssize_t
|
from test.support import bigaddrspacetest, MAX_Py_ssize_t
|
||||||
|
|
||||||
|
|
||||||
|
@ -1418,6 +1419,7 @@ def test_iterator_pickling2(self):
|
||||||
b[:] = data
|
b[:] = data
|
||||||
self.assertEqual(list(it), [])
|
self.assertEqual(list(it), [])
|
||||||
|
|
||||||
|
test_exhausted_iterator = test.list_tests.CommonTest.test_exhausted_iterator
|
||||||
|
|
||||||
class AssortedBytesTest(unittest.TestCase):
|
class AssortedBytesTest(unittest.TestCase):
|
||||||
#
|
#
|
||||||
|
|
|
@ -190,6 +190,17 @@ def test_mutating_seq_class_iter_pickle(self):
|
||||||
self.assertTrue(isinstance(it, collections.abc.Iterator))
|
self.assertTrue(isinstance(it, collections.abc.Iterator))
|
||||||
self.assertEqual(list(it), [])
|
self.assertEqual(list(it), [])
|
||||||
|
|
||||||
|
def test_mutating_seq_class_exhausted_iter(self):
|
||||||
|
a = SequenceClass(5)
|
||||||
|
exhit = iter(a)
|
||||||
|
empit = iter(a)
|
||||||
|
for x in exhit: # exhaust the iterator
|
||||||
|
next(empit) # not exhausted
|
||||||
|
a.n = 7
|
||||||
|
self.assertEqual(list(exhit), [])
|
||||||
|
self.assertEqual(list(empit), [5, 6])
|
||||||
|
self.assertEqual(list(a), [0, 1, 2, 3, 4, 5, 6])
|
||||||
|
|
||||||
# Test a new_style class with __iter__ but no next() method
|
# Test a new_style class with __iter__ but no next() method
|
||||||
def test_new_style_iter_class(self):
|
def test_new_style_iter_class(self):
|
||||||
class IterClass(object):
|
class IterClass(object):
|
||||||
|
|
Loading…
Reference in New Issue