# The suboffsets tests need sizeof(void *).
self.sizeof_void_p = get_sizeof_void_p()
- def verify(self, result, obj=-1,
- itemsize={1}, fmt=-1, readonly={1},
- ndim={1}, shape=-1, strides=-1,
- lst=-1, sliced=False, cast=False):
+ def verify(self, result, *, obj,
+ itemsize, fmt, readonly,
+ ndim, shape, strides,
+ lst, sliced=False, cast=False):
# Verify buffer contents against expected values. Default values
# are deliberately initialized to invalid types.
if shape:
self.assertEqual(result.nbytes, expected_len)
self.assertEqual(result.itemsize, itemsize)
self.assertEqual(result.format, fmt)
- self.assertEqual(result.readonly, readonly)
+ self.assertIs(result.readonly, readonly)
self.assertEqual(result.ndim, ndim)
self.assertEqual(result.shape, tuple(shape))
if not (sliced and suboffsets):
lst = nd.tolist()
# The consumer may have requested default values or a NULL format.
- ro = 0 if match(req, PyBUF_WRITABLE) else ex.readonly
+ ro = not match(req, PyBUF_WRITABLE) and ex.readonly
fmt = ex.format
itemsize = ex.itemsize
ndim = ex.ndim
itemsize = struct.calcsize(fmt)
nd = ndarray(scalar, shape=(), format=fmt)
self.verify(nd, obj=None,
- itemsize=itemsize, fmt=fmt, readonly=1,
+ itemsize=itemsize, fmt=fmt, readonly=True,
ndim=0, shape=(), strides=(),
lst=scalar)
for flags in (0, ND_PIL):
nd = ndarray(items, shape=[nitems], format=fmt, flags=flags)
self.verify(nd, obj=None,
- itemsize=itemsize, fmt=fmt, readonly=1,
+ itemsize=itemsize, fmt=fmt, readonly=True,
ndim=1, shape=(nitems,), strides=(itemsize,),
lst=items)
nd = ndarray(items, shape=shape, strides=strides,
format=fmt, offset=offset, flags=flags)
self.verify(nd, obj=None,
- itemsize=itemsize, fmt=fmt, readonly=1,
+ itemsize=itemsize, fmt=fmt, readonly=True,
ndim=1, shape=shape, strides=strides,
lst=items[::step])
strides = strides_from_shape(ndim, shape, itemsize, 'C')
lst = carray(items, shape)
self.verify(nd, obj=None,
- itemsize=itemsize, fmt=fmt, readonly=1,
+ itemsize=itemsize, fmt=fmt, readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
self.assertTrue(nd.strides == ())
mv = nd.memoryview_from_buffer()
self.verify(mv, obj=None,
- itemsize=itemsize, fmt=fmt, readonly=1,
+ itemsize=itemsize, fmt=fmt, readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
strides = strides_from_shape(ndim, shape, itemsize, 'F')
lst = farray(items, shape)
self.verify(nd, obj=None,
- itemsize=itemsize, fmt=fmt, readonly=1,
+ itemsize=itemsize, fmt=fmt, readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
self.assertEqual(mv, nd)
self.assertIs(mverr, lsterr)
self.verify(mv, obj=ex,
- itemsize=nd.itemsize, fmt=fmt, readonly=0,
+ itemsize=nd.itemsize, fmt=fmt, readonly=False,
ndim=nd.ndim, shape=nd.shape, strides=nd.strides,
lst=nd.tolist())
continue # http://projects.scipy.org/numpy/ticket/1910
z = numpy_array_from_structure(items, fmt, t)
self.verify(x, obj=None,
- itemsize=z.itemsize, fmt=fmt, readonly=0,
+ itemsize=z.itemsize, fmt=fmt, readonly=False,
ndim=z.ndim, shape=z.shape, strides=z.strides,
lst=z.tolist())
# Slice assignment of overlapping structures
# is undefined in NumPy.
self.verify(xl, obj=None,
- itemsize=zl.itemsize, fmt=fmt, readonly=0,
+ itemsize=zl.itemsize, fmt=fmt, readonly=False,
ndim=zl.ndim, shape=zl.shape,
strides=zl.strides, lst=zl.tolist())
self.verify(xr, obj=None,
- itemsize=zr.itemsize, fmt=fmt, readonly=0,
+ itemsize=zr.itemsize, fmt=fmt, readonly=False,
ndim=zr.ndim, shape=zr.shape,
strides=zr.strides, lst=zr.tolist())
lst = carray(items, shape)
self.verify(m, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
# From memoryview:
m2 = memoryview(m)
self.verify(m2, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
self.assertEqual(nd.strides, ())
m = nd.memoryview_from_buffer()
self.verify(m, obj=None,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
lst = [items] if ndim == 0 else items
self.verify(m, obj=None,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=1, shape=[ex.nbytes], strides=(1,),
lst=lst)
lst = farray(items, shape)
self.verify(m, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
# From memoryview:
m2 = memoryview(m)
self.verify(m2, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst)
lst = carray(items, shape)
self.verify(m, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=ex.strides,
lst=lst)
# From memoryview:
m2 = memoryview(m)
self.verify(m2, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=ndim, shape=shape, strides=ex.strides,
lst=lst)
m2 = m.cast(bytefmt)
lst = to_bytelist(ex)
self.verify(m2, obj=ex,
- itemsize=1, fmt=bytefmt, readonly=0,
+ itemsize=1, fmt=bytefmt, readonly=False,
ndim=1, shape=[31*srcsize], strides=(1,),
lst=lst, cast=True)
self.assertEqual(m3, ex)
lst = ex.tolist()
self.verify(m3, obj=ex,
- itemsize=srcsize, fmt=fmt, readonly=0,
+ itemsize=srcsize, fmt=fmt, readonly=False,
ndim=1, shape=[31], strides=(srcsize,),
lst=lst, cast=True)
m = memoryview(ex)
m2 = m.cast('B')
self.verify(m2, obj=ex,
- itemsize=1, fmt='B', readonly=1,
+ itemsize=1, fmt='B', readonly=True,
ndim=1, shape=destshape, strides=(1,),
lst=destitems, cast=True)
m = memoryview(ex)
m2 = m.cast('I', shape=[])
self.verify(m2, obj=ex,
- itemsize=destsize, fmt='I', readonly=1,
+ itemsize=destsize, fmt='I', readonly=True,
ndim=0, shape=(), strides=(),
lst=destitems, cast=True)
strides = nd.strides
lst = nd.tolist()
self.verify(m2, obj=ex,
- itemsize=tsize, fmt=tfmt, readonly=1,
+ itemsize=tsize, fmt=tfmt, readonly=True,
ndim=ndim, shape=tshape, strides=strides,
lst=lst, cast=True)
lst = ex.tolist()
self.verify(m3, obj=ex,
- itemsize=size, fmt=fmt, readonly=1,
+ itemsize=size, fmt=fmt, readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst, cast=True)
self.verify(m4, obj=ex,
- itemsize=size, fmt=fmt, readonly=1,
+ itemsize=size, fmt=fmt, readonly=True,
ndim=ndim, shape=shape, strides=strides,
lst=lst, cast=True)
m2 = m1.cast('B')
self.assertEqual(m2.obj, point)
self.assertEqual(m2.itemsize, 1)
- self.assertEqual(m2.readonly, 0)
+ self.assertIs(m2.readonly, False)
self.assertEqual(m2.ndim, 1)
self.assertEqual(m2.shape, (m2.nbytes,))
self.assertEqual(m2.strides, (1,))
m2 = m1.cast('c')
self.assertEqual(m2.obj, x)
self.assertEqual(m2.itemsize, 1)
- self.assertEqual(m2.readonly, 0)
+ self.assertIs(m2.readonly, False)
self.assertEqual(m2.ndim, 1)
self.assertEqual(m2.shape, (m2.nbytes,))
self.assertEqual(m2.strides, (1,))
flags=ND_WRITABLE)
m = memoryview(ex)
m[1] = True
- self.assertEqual(m[1], True)
+ self.assertIs(m[1], True)
# pack_single() exceptions:
nd = ndarray([b'x'], shape=[1], format='c', flags=ND_WRITABLE)
x = staticarray()
y = memoryview(x)
self.verify(y, obj=x,
- itemsize=1, fmt=fmt, readonly=1,
+ itemsize=1, fmt=fmt, readonly=True,
ndim=1, shape=[12], strides=[1],
lst=lst)
for i in range(12):
self.assertIs(y.obj, x)
self.assertIs(m.obj, z)
self.verify(m, obj=z,
- itemsize=1, fmt=fmt, readonly=1,
+ itemsize=1, fmt=fmt, readonly=True,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
self.assertIs(z.obj, x)
self.assertIs(m.obj, x)
self.verify(m, obj=x,
- itemsize=1, fmt=fmt, readonly=1,
+ itemsize=1, fmt=fmt, readonly=True,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
x = staticarray(legacy_mode=True)
y = memoryview(x)
self.verify(y, obj=None,
- itemsize=1, fmt=fmt, readonly=1,
+ itemsize=1, fmt=fmt, readonly=True,
ndim=1, shape=[12], strides=[1],
lst=lst)
for i in range(12):
self.assertIs(y.obj, None)
self.assertIs(m.obj, z)
self.verify(m, obj=z,
- itemsize=1, fmt=fmt, readonly=1,
+ itemsize=1, fmt=fmt, readonly=True,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
self.assertIs(z.obj, y)
self.assertIs(m.obj, y)
self.verify(m, obj=y,
- itemsize=1, fmt=fmt, readonly=1,
+ itemsize=1, fmt=fmt, readonly=True,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m