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

Method test_splice_offset_in

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

Source from the content-addressed store, hash-verified

554 @unittest.skipUnless(hasattr(os, 'splice'), 'test needs os.splice()')
555 @requires_splice_pipe
556 def test_splice_offset_in(self):
557 TESTFN4 = os_helper.TESTFN + ".4"
558 data = b'0123456789'
559 bytes_to_copy = 6
560 in_skip = 3
561
562 create_file(os_helper.TESTFN, data)
563 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
564
565 in_file = open(os_helper.TESTFN, 'rb')
566 self.addCleanup(in_file.close)
567 in_fd = in_file.fileno()
568
569 read_fd, write_fd = os.pipe()
570 self.addCleanup(lambda: os.close(read_fd))
571 self.addCleanup(lambda: os.close(write_fd))
572
573 try:
574 i = os.splice(in_fd, write_fd, bytes_to_copy, offset_src=in_skip)
575 except OSError as e:
576 # Handle the case in which Python was compiled
577 # in a system with the syscall but without support
578 # in the kernel.
579 if e.errno != errno.ENOSYS:
580 raise
581 self.skipTest(e)
582 else:
583 # The number of copied bytes can be less than
584 # the number of bytes originally requested.
585 self.assertIn(i, range(0, bytes_to_copy+1));
586
587 read = os.read(read_fd, 100)
588 # 012 are skipped (in_skip)
589 # 345678 are copied in the file (in_skip + bytes_to_copy)
590 self.assertEqual(read, data[in_skip:in_skip+i])
591
592 @unittest.skipUnless(hasattr(os, 'splice'), 'test needs os.splice()')
593 @requires_splice_pipe

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected