(self)
| 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): |
nothing calls this directly
no test coverage detected