MCPcopy Index your code
hub / github.com/python/cpython / test_memoryview_cast_zero_shape

Method test_memoryview_cast_zero_shape

Lib/test/test_buffer.py:2503–2519  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2501 self.assertRaises(ValueError, get_contiguous, nd[::-1], PyBUF_READ, 'C')
2502
2503 def test_memoryview_cast_zero_shape(self):
2504 # Casts are undefined if buffer is multidimensional and shape
2505 # contains zeros. These arrays are regarded as C-contiguous by
2506 # Numpy and PyBuffer_GetContiguous(), so they are not caught by
2507 # the test for C-contiguity in memory_cast().
2508 items = [1,2,3]
2509 for shape in ([0,3,3], [3,0,3], [0,3,3]):
2510 ex = ndarray(items, shape=shape)
2511 self.assertTrue(ex.c_contiguous)
2512 msrc = memoryview(ex)
2513 self.assertRaises(TypeError, msrc.cast, 'c')
2514 # Monodimensional empty view can be cast (issue #19014).
2515 for fmt, _, _ in iter_format(1, 'memoryview'):
2516 msrc = memoryview(b'')
2517 m = msrc.cast(fmt)
2518 self.assertEqual(m.tobytes(), b'')
2519 self.assertEqual(m.tolist(), [])
2520
2521 check_sizeof = support.check_sizeof
2522

Callers

nothing calls this directly

Calls 5

iter_formatFunction · 0.85
assertTrueMethod · 0.80
castMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected