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

Method _testReadintoMemoryview

Lib/test/test_io/test_fileio.py:98–112  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

96 self.assertEqual(n, 4)
97
98 def _testReadintoMemoryview(self):
99 self.f.write(bytes([1, 2, 0, 255]))
100 self.f.close()
101
102 m = memoryview(bytearray(b'abcdefgh'))
103 with self.FileIO(TESTFN, 'r') as f:
104 n = f.readinto(m)
105 self.assertEqual(m, b'\x01\x02\x00\xffefgh')
106 self.assertEqual(n, 4)
107
108 m = memoryview(bytearray(b'abcdefgh')).cast('H', shape=[2, 2])
109 with self.FileIO(TESTFN, 'r') as f:
110 n = f.readinto(m)
111 self.assertEqual(bytes(m), b'\x01\x02\x00\xffefgh')
112 self.assertEqual(n, 4)
113
114 def _testReadintoArray(self):
115 self.f.write(bytes([1, 2, 0, 255]))

Callers

nothing calls this directly

Calls 5

castMethod · 0.80
writeMethod · 0.45
closeMethod · 0.45
readintoMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected