summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2008-12-06 21:27:53 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2008-12-06 21:27:53 (GMT)
commit5504e893f84f07d5930094f07bcd479d859b5f0c (patch)
tree6e1f23c5a9e2ddfcb1a591fd97e07a120674e745 /Lib/test/test_bytes.py
parente6d4a9bdbc73a5314890d41a6e1e447ea848998f (diff)
downloadcpython-5504e893f84f07d5930094f07bcd479d859b5f0c.zip
cpython-5504e893f84f07d5930094f07bcd479d859b5f0c.tar.gz
cpython-5504e893f84f07d5930094f07bcd479d859b5f0c.tar.bz2
Issue #4509: bugs in bytearray with exports (buffer protocol)
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 24812a5..b1427b5 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -769,6 +769,37 @@ class ByteArrayTest(BaseBytesTest):
self.assertEqual(b, b"")
self.assertEqual(c, b"")
+ def test_resize_forbidden(self):
+ # #4509: can't resize a bytearray when there are buffer exports, even
+ # if it wouldn't reallocate the underlying buffer.
+ # Furthermore, no destructive changes to the buffer may be applied
+ # before raising the error.
+ b = bytearray(range(10))
+ v = memoryview(b)
+ def resize(n):
+ b[1:-1] = range(n + 1, 2*n - 1)
+ resize(10)
+ orig = b[:]
+ self.assertRaises(BufferError, resize, 11)
+ self.assertEquals(b, orig)
+ self.assertRaises(BufferError, resize, 9)
+ self.assertEquals(b, orig)
+ self.assertRaises(BufferError, resize, 0)
+ self.assertEquals(b, orig)
+ # Other operations implying resize
+ self.assertRaises(BufferError, b.pop, 0)
+ self.assertEquals(b, orig)
+ self.assertRaises(BufferError, b.remove, b[1])
+ self.assertEquals(b, orig)
+ def delitem():
+ del b[1]
+ self.assertRaises(BufferError, delitem)
+ self.assertEquals(b, orig)
+ # deleting a non-contiguous slice
+ def delslice():
+ b[1:-1:2] = b""
+ self.assertRaises(BufferError, delslice)
+ self.assertEquals(b, orig)
class AssortedBytesTest(unittest.TestCase):
#