Author: Manuel Jacob <[email protected]>
Branch: py3k-memoryview
Changeset: r76131:ed7ac9b0bbd8
Date: 2015-02-25 15:26 +0100
http://bitbucket.org/pypy/pypy/changeset/ed7ac9b0bbd8/
Log: Test and fix memory slices with non-bytes format.
diff --git a/pypy/objspace/std/memoryobject.py
b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -92,7 +92,7 @@
else:
buf = SubBuffer(self.buf, start * self.itemsize,
size * self.itemsize)
- return W_MemoryView(buf)
+ return W_MemoryView(buf, self.format, self.itemsize)
def descr_setitem(self, space, w_index, w_obj):
self._check_released(space)
diff --git a/pypy/objspace/std/test/test_memoryobject.py
b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -131,12 +131,27 @@
def test_int_array_buffer(self):
import array
m = memoryview(array.array('i', list(range(10))))
+ assert m.format == 'i'
+ assert m.itemsize == 4
assert len(m) == 10
assert len(m.tobytes()) == 40
assert m[0] == b'\x00\x00\x00\x00'
m[0] = b'\x00\x00\x00\x01'
assert m[0] == b'\x00\x00\x00\x01'
+ def test_int_array_slice(self):
+ import array
+ m = memoryview(array.array('i', list(range(10))))
+ slice = m[2:8]
+ assert slice.format == 'i'
+ assert slice.itemsize == 4
+ assert len(slice) == 6
+ assert len(slice.tobytes()) == 24
+ assert slice[0] in (b'\x00\x00\x00\x02', b'\x02\x00\x00\x00')
+ slice[0] = b'\x00\x00\x00\x01'
+ assert slice[0] == b'\x00\x00\x00\x01'
+ assert m[2] == b'\x00\x00\x00\x01'
+
def test_pypy_raw_address_base(self):
raises(ValueError, memoryview(b"foobar")._pypy_raw_address)
e = raises(ValueError,
memoryview(bytearray(b"foobar"))._pypy_raw_address)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit