Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_array.py @ 55113:8e8157445a55
Issue 4509: Do not modify an array if we know the change would result
in a failure due to exported buffers.
| author | Alexandre Vassalotti <alexandre@peadrop.com> |
|---|---|
| date | Sun, 05 Jul 2009 05:38:18 +0000 |
| parents | 0bb232078b8c |
| children | ab434f0dcb15 |
line wrap: on
line diff
--- a/Lib/test/test_array.py Sat Jul 04 15:18:00 2009 +0000 +++ b/Lib/test/test_array.py Sun Jul 05 05:38:18 2009 +0000 @@ -749,9 +749,25 @@ ArraySubclassWithKwargs('b', newarg=1) def test_create_from_bytes(self): + # XXX This test probably needs to be moved in a subclass or + # generalized to use self.typecode. a = array.array('H', b"1234") self.assertEqual(len(a) * a.itemsize, 4) + def test_memoryview_no_resize(self): + # Test for issue 4509. + a = array.array(self.typecode, self.example) + m = memoryview(a) + expected = m.tobytes() + self.assertRaises(BufferError, a.pop, 0) + self.assertEqual(m.tobytes(), expected) + self.assertRaises(BufferError, a.remove, a[0]) + self.assertEqual(m.tobytes(), expected) + self.assertRaises(BufferError, a.__setitem__, slice(0, 0), a) + self.assertEqual(m.tobytes(), expected) + self.assertRaises(BufferError, a.__delitem__, slice(0, len(a))) + self.assertEqual(m.tobytes(), expected) + class StringTest(BaseTest):
