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

Method test_copy_file_range

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

Source from the content-addressed store, hash-verified

438
439 @unittest.skipUnless(hasattr(os, 'copy_file_range'), 'test needs os.copy_file_range()')
440 def test_copy_file_range(self):
441 TESTFN2 = os_helper.TESTFN + ".3"
442 data = b'0123456789'
443
444 create_file(os_helper.TESTFN, data)
445 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
446
447 in_file = open(os_helper.TESTFN, 'rb')
448 self.addCleanup(in_file.close)
449 in_fd = in_file.fileno()
450
451 out_file = open(TESTFN2, 'w+b')
452 self.addCleanup(os_helper.unlink, TESTFN2)
453 self.addCleanup(out_file.close)
454 out_fd = out_file.fileno()
455
456 try:
457 i = os.copy_file_range(in_fd, out_fd, 5)
458 except OSError as e:
459 # Handle the case in which Python was compiled
460 # in a system with the syscall but without support
461 # in the kernel.
462 if e.errno != errno.ENOSYS:
463 raise
464 self.skipTest(e)
465 else:
466 # The number of copied bytes can be less than
467 # the number of bytes originally requested.
468 self.assertIn(i, range(0, 6));
469
470 with open(TESTFN2, 'rb') as in_file:
471 self.assertEqual(in_file.read(), data[:i])
472
473 @unittest.skipUnless(hasattr(os, 'copy_file_range'), 'test needs os.copy_file_range()')
474 def test_copy_file_range_offset(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
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected