cpython: b4ea00d50e7e (original) (raw)
Mercurial > cpython
changeset 100804:b4ea00d50e7e
Issue #26492: Added additional tests for exhausted iterators of mutable sequences. [#26492]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Wed, 30 Mar 2016 21:01:45 +0300 |
parents | 73ce47d4a7b2(current diff)89ba67ee83d6(diff) |
children | b6eebe7cf5ae |
files | Lib/test/test_bytes.py |
diffstat | 3 files changed, 24 insertions(+), 0 deletions(-)[+] [-] Lib/test/list_tests.py 11 Lib/test/test_bytes.py 2 Lib/test/test_iter.py 11 |
line wrap: on
line diff
--- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -593,3 +593,14 @@ class CommonTest(seq_tests.CommonTest): def iter(self): raise KeyboardInterrupt self.assertRaises(KeyboardInterrupt, list, F()) +
- def test_exhausted_iterator(self):
a = self.type2test([1, 2, 3])[](#l1.9)
exhit = iter(a)[](#l1.10)
empit = iter(a)[](#l1.11)
for x in exhit: # exhaust the iterator[](#l1.12)
next(empit) # not exhausted[](#l1.13)
a.append(9)[](#l1.14)
self.assertEqual(list(exhit), [])[](#l1.15)
self.assertEqual(list(empit), [9])[](#l1.16)
self.assertEqual(a, self.type2test([1, 2, 3, 9]))[](#l1.17)
--- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -17,6 +17,7 @@ import unittest import test.support import test.string_tests import test.buffer_tests +import test.list_tests from test.support import bigaddrspacetest, MAX_Py_ssize_t @@ -1418,6 +1419,7 @@ class ByteArrayTest(BaseBytesTest, unitt b[:] = data self.assertEqual(list(it), [])
class AssortedBytesTest(unittest.TestCase): #
--- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -190,6 +190,17 @@ class TestCase(unittest.TestCase): self.assertTrue(isinstance(it, collections.abc.Iterator)) self.assertEqual(list(it), [])
- def test_mutating_seq_class_exhausted_iter(self):
a = SequenceClass(5)[](#l3.8)
exhit = iter(a)[](#l3.9)
empit = iter(a)[](#l3.10)
for x in exhit: # exhaust the iterator[](#l3.11)
next(empit) # not exhausted[](#l3.12)
a.n = 7[](#l3.13)
self.assertEqual(list(exhit), [])[](#l3.14)
self.assertEqual(list(empit), [5, 6])[](#l3.15)
self.assertEqual(list(a), [0, 1, 2, 3, 4, 5, 6])[](#l3.16)
+ # Test a new_style class with iter but no next() method def test_new_style_iter_class(self): class IterClass(object):