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

Method test_copy_file_range_offset

Lib/test/test_os.py:472–514  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

470
471 @unittest.skipUnless(hasattr(os, 'copy_file_range'), 'test needs os.copy_file_range()')
472 def test_copy_file_range_offset(self):
473 TESTFN4 = os_helper.TESTFN + ".4"
474 data = b'0123456789'
475 bytes_to_copy = 6
476 in_skip = 3
477 out_seek = 5
478
479 create_file(os_helper.TESTFN, data)
480 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
481
482 in_file = open(os_helper.TESTFN, 'rb')
483 self.addCleanup(in_file.close)
484 in_fd = in_file.fileno()
485
486 out_file = open(TESTFN4, 'w+b')
487 self.addCleanup(os_helper.unlink, TESTFN4)
488 self.addCleanup(out_file.close)
489 out_fd = out_file.fileno()
490
491 try:
492 i = os.copy_file_range(in_fd, out_fd, bytes_to_copy,
493 offset_src=in_skip,
494 offset_dst=out_seek)
495 except OSError as e:
496 # Handle the case in which Python was compiled
497 # in a system with the syscall but without support
498 # in the kernel.
499 if e.errno != errno.ENOSYS:
500 raise
501 self.skipTest(e)
502 else:
503 # The number of copied bytes can be less than
504 # the number of bytes originally requested.
505 self.assertIn(i, range(0, bytes_to_copy+1));
506
507 with open(TESTFN4, 'rb') as in_file:
508 read = in_file.read()
509 # seeked bytes (5) are zero'ed
510 self.assertEqual(read[:out_seek], b'\x00'*out_seek)
511 # 012 are skipped (in_skip)
512 # 345678 are copied in the file (in_skip + bytes_to_copy)
513 self.assertEqual(read[out_seek:],
514 data[in_skip:in_skip+i])
515
516 @unittest.skipUnless(hasattr(os, 'splice'), 'test needs os.splice()')
517 def test_splice_invalid_values(self):

Callers

nothing calls this directly

Calls 8

addCleanupMethod · 0.80
skipTestMethod · 0.80
assertInMethod · 0.80
create_fileFunction · 0.70
openFunction · 0.50
filenoMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected