summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-30 18:11:16 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-30 18:11:16 (GMT)
commitab0d198c7a6b2133ba5f782d7b951fef00ae615c (patch)
treea06cc9e22092d9e4cbb0c7bc5aaf96d5eac72ab6 /Lib
parentf39c0ac62f90842b790a41f1b0ddd51a6e3d8dc2 (diff)
downloadcpython-ab0d198c7a6b2133ba5f782d7b951fef00ae615c.zip
cpython-ab0d198c7a6b2133ba5f782d7b951fef00ae615c.tar.gz
cpython-ab0d198c7a6b2133ba5f782d7b951fef00ae615c.tar.bz2
Issue #26492: Exhausted iterator of array.array now conforms with the behavior
of iterators of other mutable sequences: it lefts exhausted even if iterated array is extended.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_array.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 482526e..b4f2bf8 100644
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -318,8 +318,19 @@ class BaseTest:
d = pickle.dumps((itorig, orig), proto)
it, a = pickle.loads(d)
a.fromlist(data2)
- self.assertEqual(type(it), type(itorig))
- self.assertEqual(list(it), data2)
+ self.assertEqual(list(it), [])
+
+ def test_exhausted_iterator(self):
+ a = array.array(self.typecode, self.example)
+ self.assertEqual(list(a), list(self.example))
+ exhit = iter(a)
+ empit = iter(a)
+ for x in exhit: # exhaust the iterator
+ next(empit) # not exhausted
+ a.append(self.outside)
+ self.assertEqual(list(exhit), [])
+ self.assertEqual(list(empit), [self.outside])
+ self.assertEqual(list(a), list(self.example) + [self.outside])
def test_insert(self):
a = array.array(self.typecode, self.example)
@@ -1070,6 +1081,12 @@ class BaseTest:
a = array.array('B', b"")
self.assertRaises(BufferError, getbuffer_with_null_view, a)
+ def test_free_after_iterating(self):
+ support.check_free_after_iterating(self, iter, array.array,
+ (self.typecode,))
+ support.check_free_after_iterating(self, reversed, array.array,
+ (self.typecode,))
+
class StringTest(BaseTest):
def test_setitem(self):