[pypy-svn] pypy default: - Mark the undocumented bytes.__alloc__() as an implementation
arigo
commits-noreply at bitbucket.org
Tue Feb 8 17:58:37 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41702:1b4cca12e352
Date: 2011-02-08 17:58 +0100
http://bitbucket.org/pypy/pypy/changeset/1b4cca12e352/
Log: - Mark the undocumented bytes.__alloc__() as an implementation
detail for now.
- Test the different behavior we have w.r.t. taking a buffer() on
a bytearray and mutating the bytearray at the same time.
diff --git a/lib-python/2.7.0/test/test_bytes.py b/lib-python/modified-2.7.0/test/test_bytes.py
copy from lib-python/2.7.0/test/test_bytes.py
copy to lib-python/modified-2.7.0/test/test_bytes.py
--- a/lib-python/2.7.0/test/test_bytes.py
+++ b/lib-python/modified-2.7.0/test/test_bytes.py
@@ -632,6 +632,7 @@
self.assertEqual(b, b1)
self.assertTrue(b is b1)
+ @test.test_support.impl_detail("undocumented bytes.__alloc__()")
def test_alloc(self):
b = bytearray()
alloc = b.__alloc__()
@@ -759,6 +760,8 @@
self.assertEqual(b, b"")
self.assertEqual(c, b"")
+ @test.test_support.impl_detail(
+ "resizing semantics of CPython rely on refcounting")
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.
@@ -791,6 +794,26 @@
self.assertRaises(BufferError, delslice)
self.assertEquals(b, orig)
+ @test.test_support.impl_detail("resizing semantics", cpython=False)
+ def test_resize_forbidden_non_cpython(self):
+ # on non-CPython implementations, we cannot prevent changes to
+ # bytearrays just because there are buffers around. Instead,
+ # we get (on PyPy) a buffer that follows the changes and resizes.
+ b = bytearray(range(10))
+ for v in [memoryview(b), buffer(b)]:
+ b[5] = 99
+ self.assertIn(v[5], (99, chr(99)))
+ b[5] = 100
+ b += b
+ b += b
+ b += b
+ self.assertEquals(len(v), 80)
+ self.assertIn(v[5], (100, chr(100)))
+ self.assertIn(v[79], (9, chr(9)))
+ del b[10:]
+ self.assertRaises(IndexError, lambda: v[10])
+ self.assertEquals(len(v), 10)
+
def test_empty_bytearray(self):
# Issue #7561: operations on empty bytearrays could crash in many
# situations, due to a fragile implementation of the
More information about the Pypy-commit
mailing list