◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
80 changes: 40 additions & 40 deletions Lib/test/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,10 @@ def setUp(self):
# 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):
# Verify buffer contents against expected values. Default values
# are deliberately initialized to invalid types.
if shape:
Expand Down @@ -800,7 +800,7 @@ def verify(self, result, obj=-1,
self.assertEqual(result.nbytes, expected_len)
self.assertEqual(result.itemsize, itemsize)
self.assertEqual(result.format, fmt)
self.assertEqual(result.readonly, readonly)
self.assertEqual(result.ndim, ndim)
self.assertEqual(result.shape, tuple(shape))
if not (sliced and suboffsets):
Expand Down Expand Up @@ -978,7 +978,7 @@ def match(req, flag):
lst = nd.tolist()

# The consumer may have requested default values or a NULL format.
ro = 0 if match(req, PyBUF_WRITABLE) else ex.readonly
fmt = ex.format
itemsize = ex.itemsize
ndim = ex.ndim
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def test_ndarray_format_scalar(self):
itemsize = struct.calcsize(fmt)
nd = ndarray(scalar, shape=(), format=fmt)
self.verify(nd, obj=None,
itemsize=itemsize, fmt=fmt, readonly=1,
ndim=0, shape=(), strides=(),
lst=scalar)

Expand All @@ -1296,7 +1296,7 @@ def test_ndarray_format_shape(self):
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,
ndim=1, shape=(nitems,), strides=(itemsize,),
lst=items)

Expand All @@ -1317,7 +1317,7 @@ def test_ndarray_format_strides(self):
nd = ndarray(items, shape=shape, strides=strides,
format=fmt, offset=offset, flags=flags)
self.verify(nd, obj=None,
itemsize=itemsize, fmt=fmt, readonly=1,
ndim=1, shape=shape, strides=strides,
lst=items[::step])

Expand Down Expand Up @@ -1346,7 +1346,7 @@ def test_ndarray_multidim(self):
strides = strides_from_shape(ndim, shape, itemsize, 'C')
lst = carray(items, shape)
self.verify(nd, obj=None,
itemsize=itemsize, fmt=fmt, readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

Expand All @@ -1357,7 +1357,7 @@ def test_ndarray_multidim(self):
self.assertTrue(nd.strides == ())
mv = nd.memoryview_from_buffer()
self.verify(mv, obj=None,
itemsize=itemsize, fmt=fmt, readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

Expand All @@ -1368,7 +1368,7 @@ def test_ndarray_multidim(self):
strides = strides_from_shape(ndim, shape, itemsize, 'F')
lst = farray(items, shape)
self.verify(nd, obj=None,
itemsize=itemsize, fmt=fmt, readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

Expand Down Expand Up @@ -1816,7 +1816,7 @@ def test_ndarray_slice_assign_single(self):
self.assertEqual(mv, nd)
self.assertIs(mverr, lsterr)
self.verify(mv, obj=ex,
itemsize=nd.itemsize, fmt=fmt, readonly=0,
ndim=nd.ndim, shape=nd.shape, strides=nd.strides,
lst=nd.tolist())

Expand Down Expand Up @@ -1890,7 +1890,7 @@ def test_ndarray_random(self):
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,
ndim=z.ndim, shape=z.shape, strides=z.strides,
lst=z.tolist())

Expand Down Expand Up @@ -1975,12 +1975,12 @@ def test_ndarray_random_slice_assign(self):
# Slice assignment of overlapping structures
# is undefined in NumPy.
self.verify(xl, obj=None,
itemsize=zl.itemsize, fmt=fmt, readonly=0,
ndim=zl.ndim, shape=zl.shape,
strides=zl.strides, lst=zl.tolist())

self.verify(xr, obj=None,
itemsize=zr.itemsize, fmt=fmt, readonly=0,
ndim=zr.ndim, shape=zr.shape,
strides=zr.strides, lst=zr.tolist())

Expand Up @@ -2358,14 +2358,14 @@ def test_memoryview_construction(self):
lst = carray(items, shape)

self.verify(m, obj=ex,
itemsize=1, fmt='B', readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

# From memoryview:
m2 = memoryview(m)
self.verify(m2, obj=ex,
itemsize=1, fmt='B', readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

@@ -2374,7 +2374,7 @@ def test_memoryview_construction(self):
self.assertEqual(nd.strides, ())
m = nd.memoryview_from_buffer()
self.verify(m, obj=None,
itemsize=1, fmt='B', readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

Expand All @@ -2387,7 +2387,7 @@ def test_memoryview_construction(self):

lst = [items] if ndim == 0 else items
self.verify(m, obj=None,
itemsize=1, fmt='B', readonly=1,
ndim=1, shape=[ex.nbytes], strides=(1,),
lst=lst)

Expand All @@ -2405,14 +2405,14 @@ def test_memoryview_construction(self):
lst = farray(items, shape)

self.verify(m, obj=ex,
itemsize=1, fmt='B', readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

# From memoryview:
m2 = memoryview(m)
self.verify(m2, obj=ex,
itemsize=1, fmt='B', readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst)

Expand All @@ -2427,14 +2427,14 @@ def test_memoryview_construction(self):
lst = carray(items, shape)

self.verify(m, obj=ex,
itemsize=1, fmt='B', readonly=1,
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,
ndim=ndim, shape=shape, strides=ex.strides,
lst=lst)

Expand Up @@ -2684,15 +2684,15 @@ def iter_roundtrip(ex, m, items, fmt):
m2 = m.cast(bytefmt)
lst = to_bytelist(ex)
self.verify(m2, obj=ex,
itemsize=1, fmt=bytefmt, readonly=0,
ndim=1, shape=[31*srcsize], strides=(1,),
lst=lst, cast=True)

m3 = m2.cast(fmt)
self.assertEqual(m3, ex)
lst = ex.tolist()
self.verify(m3, obj=ex,
itemsize=srcsize, fmt=fmt, readonly=0,
ndim=1, shape=[31], strides=(srcsize,),
lst=lst, cast=True)

Expand All @@ -2703,7 +2703,7 @@ def iter_roundtrip(ex, m, items, fmt):
m = memoryview(ex)
m2 = m.cast('B')
self.verify(m2, obj=ex,
itemsize=1, fmt='B', readonly=1,
ndim=1, shape=destshape, strides=(1,),
lst=destitems, cast=True)

Expand All @@ -2714,7 +2714,7 @@ def iter_roundtrip(ex, m, items, fmt):
m = memoryview(ex)
m2 = m.cast('I', shape=[])
self.verify(m2, obj=ex,
itemsize=destsize, fmt='I', readonly=1,
ndim=0, shape=(), strides=(),
lst=destitems, cast=True)

Expand Down @@ -2763,7 +2763,7 @@ def test_memoryview_cast_1D_ND(self):
strides = nd.strides
lst = nd.tolist()
self.verify(m2, obj=ex,
itemsize=tsize, fmt=tfmt, readonly=1,
ndim=ndim, shape=tshape, strides=strides,
lst=lst, cast=True)

Expand All @@ -2775,12 +2775,12 @@ def test_memoryview_cast_1D_ND(self):
lst = ex.tolist()

self.verify(m3, obj=ex,
itemsize=size, fmt=fmt, readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst, cast=True)

self.verify(m4, obj=ex,
itemsize=size, fmt=fmt, readonly=1,
ndim=ndim, shape=shape, strides=strides,
lst=lst, cast=True)

Expand All @@ -2793,7 +2793,7 @@ class BEPoint(ctypes.BigEndianStructure):
m2 = m1.cast('B')
self.assertEqual(m2.obj, point)
self.assertEqual(m2.itemsize, 1)
self.assertEqual(m2.readonly, 0)
self.assertEqual(m2.ndim, 1)
self.assertEqual(m2.shape, (m2.nbytes,))
self.assertEqual(m2.strides, (1,))
Expand All @@ -2804,7 +2804,7 @@ class BEPoint(ctypes.BigEndianStructure):
m2 = m1.cast('c')
self.assertEqual(m2.obj, x)
self.assertEqual(m2.itemsize, 1)
self.assertEqual(m2.readonly, 0)
self.assertEqual(m2.ndim, 1)
self.assertEqual(m2.shape, (m2.nbytes,))
self.assertEqual(m2.strides, (1,))
Expand Down Expand Up @@ -2972,7 +2972,7 @@ def test_memoryview_assign(self):
flags=ND_WRITABLE)
m = memoryview(ex)
m[1] = True
self.assertEqual(m[1], True)

# pack_single() exceptions:
nd = ndarray([b'x'], shape=[1], format='c', flags=ND_WRITABLE)
Expand Down Expand Up @@ -4306,7 +4306,7 @@ def test_memoryview_from_static_exporter(self):
x = staticarray()
y = memoryview(x)
self.verify(y, obj=x,
itemsize=1, fmt=fmt, readonly=1,
ndim=1, shape=[12], strides=[1],
lst=lst)
for i in range(12):
Expand All @@ -4326,7 +4326,7 @@ def test_memoryview_from_static_exporter(self):
self.assertIs(y.obj, x)
self.assertIs(m.obj, z)
self.verify(m, obj=z,
itemsize=1, fmt=fmt, readonly=1,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
Expand All @@ -4339,7 +4339,7 @@ def test_memoryview_from_static_exporter(self):
self.assertIs(z.obj, x)
self.assertIs(m.obj, x)
self.verify(m, obj=x,
itemsize=1, fmt=fmt, readonly=1,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
Expand All @@ -4348,7 +4348,7 @@ def test_memoryview_from_static_exporter(self):
x = staticarray(legacy_mode=True)
y = memoryview(x)
self.verify(y, obj=None,
itemsize=1, fmt=fmt, readonly=1,
ndim=1, shape=[12], strides=[1],
lst=lst)
for i in range(12):
Expand All @@ -4368,7 +4368,7 @@ def test_memoryview_from_static_exporter(self):
self.assertIs(y.obj, None)
self.assertIs(m.obj, z)
self.verify(m, obj=z,
itemsize=1, fmt=fmt, readonly=1,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
@@ -4383,7 +4383,7 @@ def test_memoryview_from_static_exporter(self):
self.assertIs(z.obj, y)
self.assertIs(m.obj, y)
self.verify(m, obj=y,
itemsize=1, fmt=fmt, readonly=1,
ndim=1, shape=[12], strides=[1],
lst=lst)
del x, y, z, m
Expand Down
2 changes: 1 addition & 1 deletion Modules/_testbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ static PyObject *
ndarray_get_readonly(NDArrayObject *self, void *closure)
{
Py_buffer *base = &self->head->base;
return PyLong_FromLong(base->readonly);
}

static PyObject *
Expand Down
Toggle all file notes Toggle all file annotations