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

Method test_copy_file_range_offset

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

Source from the content-addressed store, hash-verified

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