def test_flags_list(self, mock_tee): """Test handling of flag lists""" tee(1, 2, 3, [splice.SPLICE_F_MOVE | splice.SPLICE_F_NONBLOCK]) flags = splice.SPLICE_F_MOVE | splice.SPLICE_F_NONBLOCK self.assertEqual(mock_tee.call_args, ((1, 2, 3, flags), {})) mock_tee.reset_mock() tee(1, 2, 3, []) self.assertEqual(mock_tee.call_args, ((1, 2, 3, 0), {}))
def test_fileno(self, mock_tee): """Test handling of file-descriptors""" with pipe() as (pa, pb): tee(pa, pb, 3, 0) self.assertEqual(mock_tee.call_args, ((pa, pb, 3, 0), {})) mock_tee.reset_mock() tee(os.fdopen(pa, "r"), os.fdopen(pb, "w"), 3, 0) self.assertEqual(mock_tee.call_args, ((pa, pb, 3, 0), {}))
def test_errno(self): """Test handling of failures""" # Invoke EBADF by using a read-only FD as fd_out with open("/dev/null", "r") as fd: err = errno.EBADF msg = r"\[Errno %d\] tee: %s" % (err, os.strerror(err)) try: tee(fd, fd, 3, 0) except IOError as e: self.assertTrue(re.match(msg, str(e))) else: self.fail("Expected IOError was not raised") self.assertEqual(ctypes.get_errno(), 0)
def test_errno(self): '''Test handling of failures''' # Invoke EBADF by using a read-only FD as fd_out with open('/dev/null', 'r') as fd: err = errno.EBADF msg = r'\[Errno %d\] tee: %s' % (err, os.strerror(err)) try: tee(fd, fd, 3, 0) except IOError as e: self.assertTrue(re.match(msg, str(e))) else: self.fail('Expected IOError was not raised') self.assertEqual(ctypes.get_errno(), 0)
def test_tee_pipe_to_pipe(self): '''Test `tee` from a pipe to a pipe''' with pipe() as (p1a, p1b), pipe() as (p2a, p2b): os.write(p1b, 'abcdef') res = tee(p1a, p2b, 3, 0) self.assertEqual(res, 3) self.assertEqual(os.read(p2a, 3), 'abc') self.assertEqual(os.read(p1a, 6), 'abcdef')
def test_tee_pipe_to_pipe(self): """Test `tee` from a pipe to a pipe""" with pipe() as (p1a, p1b): with pipe() as (p2a, p2b): os.write(p1b, "abcdef") res = tee(p1a, p2b, 3, 0) self.assertEqual(res, 3) self.assertEqual(os.read(p2a, 3), "abc") self.assertEqual(os.read(p1a, 6), "abcdef")
def test_tee_pipe_to_pipe(self): '''Test `tee` from a pipe to a pipe''' with pipe() as (p1a, p1b): with pipe() as (p2a, p2b): os.write(p1b, 'abcdef') res = tee(p1a, p2b, 3, 0) self.assertEqual(res, 3) self.assertEqual(os.read(p2a, 3), 'abc') self.assertEqual(os.read(p1a, 6), 'abcdef')