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

Method test_memoryview_serializing

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

Source from the content-addressed store, hash-verified

4106 self.assertTrue(m.c_contiguous)
4107
4108 def test_memoryview_serializing(self):
4109
4110 # C-contiguous
4111 size = struct.calcsize('i')
4112 a = array.array('i', [1,2,3,4,5])
4113 m = memoryview(a)
4114 buf = io.BytesIO(m)
4115 b = bytearray(5*size)
4116 buf.readinto(b)
4117 self.assertEqual(m.tobytes(), b)
4118
4119 # C-contiguous, multi-dimensional
4120 size = struct.calcsize('L')
4121 nd = ndarray(list(range(12)), shape=[2,3,2], format="L")
4122 m = memoryview(nd)
4123 buf = io.BytesIO(m)
4124 b = bytearray(2*3*2*size)
4125 buf.readinto(b)
4126 self.assertEqual(m.tobytes(), b)
4127
4128 # Fortran contiguous, multi-dimensional
4129 #size = struct.calcsize('L')
4130 #nd = ndarray(list(range(12)), shape=[2,3,2], format="L",
4131 # flags=ND_FORTRAN)
4132 #m = memoryview(nd)
4133 #buf = io.BytesIO(m)
4134 #b = bytearray(2*3*2*size)
4135 #buf.readinto(b)
4136 #self.assertEqual(m.tobytes(), b)
4137
4138 def test_memoryview_hash(self):
4139

Callers

nothing calls this directly

Calls 3

listClass · 0.85
readintoMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected