[Python-checkins] cpython (2.7): Issue #26492: Added additional tests for exhausted iterators of mutable
serhiy.storchaka
python-checkins at python.org
Wed Mar 30 14:11:45 EDT 2016
https://hg.python.org/cpython/rev/249ef9d02aa6
changeset: 100805:249ef9d02aa6
branch: 2.7
parent: 100802:cff06d875678
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Mar 30 21:02:00 2016 +0300
summary:
Issue #26492: Added additional tests for exhausted iterators of mutable sequences.
files:
Lib/test/list_tests.py | 11 +++++++++++
Lib/test/test_bytes.py | 10 ++++++++++
Lib/test/test_iter.py | 11 +++++++++++
3 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -532,3 +532,14 @@
def __iter__(self):
raise KeyboardInterrupt
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]))
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -900,6 +900,16 @@
# PyByteArray_AS_STRING() C macro.
self.assertRaises(ValueError, int, bytearray(b''))
+ 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]))
class AssortedBytesTest(unittest.TestCase):
#
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -122,6 +122,17 @@
def test_seq_class_iter(self):
self.check_iterator(iter(SequenceClass(10)), range(10))
+ 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
def test_new_style_iter_class(self):
class IterClass(object):
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list