MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_large_readinto

Method test_large_readinto

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

Source from the content-addressed store, hash-verified

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