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

Method test_splice

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

Source from the content-addressed store, hash-verified

523 @unittest.skipUnless(hasattr(os, 'splice'), 'test needs os.splice()')
524 @requires_splice_pipe
525 def test_splice(self):
526 TESTFN2 = os_helper.TESTFN + ".3"
527 data = b'0123456789'
528
529 create_file(os_helper.TESTFN, data)
530 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
531
532 in_file = open(os_helper.TESTFN, 'rb')
533 self.addCleanup(in_file.close)
534 in_fd = in_file.fileno()
535
536 read_fd, write_fd = os.pipe()
537 self.addCleanup(lambda: os.close(read_fd))
538 self.addCleanup(lambda: os.close(write_fd))
539
540 try:
541 i = os.splice(in_fd, write_fd, 5)
542 except OSError as e:
543 # Handle the case in which Python was compiled
544 # in a system with the syscall but without support
545 # in the kernel.
546 if e.errno != errno.ENOSYS:
547 raise
548 self.skipTest(e)
549 else:
550 # The number of copied bytes can be less than
551 # the number of bytes originally requested.
552 self.assertIn(i, range(0, 6));
553
554 self.assertEqual(os.read(read_fd, 100), data[:i])
555
556 @unittest.skipUnless(hasattr(os, 'splice'), 'test needs os.splice()')
557 @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
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected