[pypy-commit] pypy setitem2d: test for 2d memoryview.__setitem__, passes with -A (issue bb-3028)

mattip pypy.commits at gmail.com
Wed Jun 19 13:47:10 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: setitem2d
Changeset: r96828:06767d845ae4
Date: 2019-06-19 20:46 +0300
http://bitbucket.org/pypy/pypy/changeset/06767d845ae4/

Log:	test for 2d memoryview.__setitem__, passes with -A (issue bb-3028)

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
@@ -184,7 +184,7 @@
         if self.view.readonly:
             raise oefmt(space.w_TypeError, "cannot modify read-only memory")
         if space.isinstance_w(w_index, space.w_tuple):
-            raise oefmt(space.w_NotImplementedError, "")
+            raise oefmt(space.w_NotImplementedError, "only 1d setitem supported")
         start, stop, step, size = space.decode_index4(w_index, self.getlength())
         is_slice = space.isinstance_w(w_index, space.w_slice)
         start, stop, step, slicelength = self._decode_index(space, w_index, is_slice)
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
@@ -287,6 +287,12 @@
         assert m2.itemsize == m1.itemsize
         assert m2.shape == m1.shape
 
+    def test_2d(self):
+        m = memoryview(bytearray(b'1234123412341234')).cast('b', shape=(4, 4))
+        assert m[2, 3] == ord('4')
+        m[2, 3] = ord('z')
+        assert m[2, 3] == ord('z') 
+
 class AppTestCtypes(object):
     spaceconfig = dict(usemodules=['sys', '_rawffi'])
 


More information about the pypy-commit mailing list