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

Method test_large_readinto

Lib/test/test_os/test_os.py:348–362  ·  view source on GitHub ↗
(self, size)

Source from the content-addressed store, hash-verified

346 "needs INT_MAX < PY_SSIZE_T_MAX")
347 @support.bigmemtest(size=INT_MAX + 10, memuse=1, dry_run=False)
348 def test_large_readinto(self, size):
349 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
350 create_file(os_helper.TESTFN, b'test')
351
352 # Issue #21932: For readinto the buffer contains the length rather than
353 # a length being passed explicitly to read, should still get capped to a
354 # valid size / not raise an OverflowError for sizes larger than INT_MAX.
355 buffer = bytearray(INT_MAX + 10)
356 with open(os_helper.TESTFN, "rb") as fp:
357 length = os.readinto(fp.fileno(), buffer)
358
359 # The test does not try to read more than 2 GiB at once because the
360 # operating system is free to return less bytes than requested.
361 self.assertEqual(length, 4)
362 self.assertEqual(buffer[:4], b'test')
363
364 def test_write(self):
365 # os.write() accepts bytes- and buffer-like objects but not strings

Callers

nothing calls this directly

Calls 6

addCleanupMethod · 0.80
create_fileFunction · 0.70
openFunction · 0.50
readintoMethod · 0.45
filenoMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected