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

Method test_memoryview_tobytes

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

Source from the content-addressed store, hash-verified

3954 self.assertEqual(m1, m1)
3955
3956 def test_memoryview_tobytes(self):
3957 # Many implicit tests are already in self.verify().
3958
3959 t = (-529, 576, -625, 676, -729)
3960
3961 nd = ndarray(t, shape=[5], format='@h')
3962 m = memoryview(nd)
3963 self.assertEqual(m, nd)
3964 self.assertEqual(m.tobytes(), nd.tobytes())
3965
3966 nd = ndarray([t], shape=[1], format='>hQiLl')
3967 m = memoryview(nd)
3968 self.assertEqual(m, nd)
3969 self.assertEqual(m.tobytes(), nd.tobytes())
3970
3971 nd = ndarray([t for _ in range(12)], shape=[2,2,3], format='=hQiLl')
3972 m = memoryview(nd)
3973 self.assertEqual(m, nd)
3974 self.assertEqual(m.tobytes(), nd.tobytes())
3975
3976 nd = ndarray([t for _ in range(120)], shape=[5,2,2,3,2],
3977 format='<hQiLl')
3978 m = memoryview(nd)
3979 self.assertEqual(m, nd)
3980 self.assertEqual(m.tobytes(), nd.tobytes())
3981
3982 # Unknown formats are handled: tobytes() purely depends on itemsize.
3983 if ctypes:
3984 # format: "T{>l:x:>l:y:}"
3985 class BEPoint(ctypes.BigEndianStructure):
3986 _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]
3987 point = BEPoint(100, 200)
3988 a = memoryview(point)
3989 self.assertEqual(a.tobytes(), bytes(point))
3990
3991 def test_memoryview_get_contiguous(self):
3992 # Many implicit tests are already in self.verify().

Callers

nothing calls this directly

Calls 2

BEPointClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected