def test_try_write(self): self.buffer = b'' self.bytes_written = 0 def on_read(connection, data, status): self.buffer += data connection.stop_read() def on_connection(pipe_handle, status): client = uv.Pipe(pipe_handle.loop) pipe_handle.accept(client) client.start_read(on_read) pipe_handle.close() def on_timeout(timer): try: self.bytes_written = self.client.try_write(b'hello') except uv.error.TemporaryUnavailableError: self.server.close() finally: timer.close() self.server = uv.Pipe(self.loop) self.server.bind(TEST_PIPE1) self.server.listen(on_connection) self.client = uv.Pipe(self.loop) self.client.connect(TEST_PIPE1) self.timer = uv.Timer(self.loop) self.timer.start(on_timeout, 1, 0) self.loop.run() self.assert_equal(self.buffer, b'hello'[:self.bytes_written])
def test_process_hello(self): arguments = [sys.executable, PROGRAM_HELLO] self.buffer = b'' self.returncode = None def on_exit(process_handle, returncode, term_signal): self.returncode = returncode def on_read(pipe_handle, data, status): if data: self.buffer += data self.pipe = uv.Pipe(self.loop) self.pipe.bind(TEST_PIPE1) self.process = uv.Process(self.loop, arguments, stdout=uv.process.PIPE, stdio=[self.pipe], callback=on_exit) self.process.stdout.start_read(on_read) self.loop.run() self.assert_equal(self.buffer.strip(), b'hello') self.assert_equal(self.returncode, 1) self.assert_not_equal(self.process.pid, None) self.assert_raises(uv.error.UVError, self.process.kill) self.process.close() self.assert_raises(uv.HandleClosedError, self.process.kill) with self.should_raise(uv.HandleClosedError): pid = self.process.pid
def test_peername(self): def on_connect(stream, status): self.assert_equal(status, uv.error.STATUS_SUCCESS) #self.assert_equal(request.stream.peername, TEST_PIPE1) stream.close() def on_connection(handle, status): self.assert_equal(status, uv.error.STATUS_SUCCESS) handle.close() self.pipe1 = uv.Pipe(self.loop) self.pipe1.bind(TEST_PIPE1) self.pipe1.listen(on_connection) self.pipe2 = uv.Pipe(self.loop) self.pipe2.connect(TEST_PIPE1, callback=on_connect) self.loop.run()
def test_connect_bad(self): def on_connect(stream, status): self.assert_not_equal(status, uv.error.STATUS_SUCCESS) stream.close() self.pipe = uv.Pipe(self.loop) self.pipe.connect(BAD_PIPE, callback=on_connect) self.loop.run()
def test_closed(self): self.pipe = uv.Pipe(self.loop) self.pipe.close() self.assert_false(self.pipe.readable) self.assert_false(self.pipe.writable) self.assert_raises(uv.HandleClosedError, self.pipe.shutdown) self.assert_raises(uv.HandleClosedError, self.pipe.listen, None) self.assert_raises(uv.HandleClosedError, self.pipe.start_read, None) self.assert_is(self.pipe.stop_read(), None) self.assert_raises(uv.HandleClosedError, self.pipe.write, b'') self.assert_raises(uv.HandleClosedError, self.pipe.try_write, b'') self.assert_raises(uv.HandleClosedError, self.pipe.accept, None)
def test_closed(self): self.pipe = uv.Pipe(self.loop) self.pipe.close() self.assert_raises(uv.error.HandleError, self.pipe.open, 0) self.assert_equal(self.pipe.pending_count, 0) self.assert_equal(self.pipe.pending_type, None) #self.assert_raises(uv.error.HandleClosedError, self.pipe.pending_accept) self.assert_raises(uv.error.HandleClosedError, self.pipe.pending_instances, 100) #with self.should_raise(uv.error.HandleClosedError): # sockname = self.pipe.sockname #with self.should_raise(uv.error.HandleClosedError): # peername = self.pipe.peername self.assert_raises(uv.error.HandleClosedError, self.pipe.bind, '') self.assert_raises(uv.error.HandleClosedError, self.pipe.connect, '')
def test_pipe_open(self): unix_socket = socket.socket(family=socket.AF_UNIX) self.pipe = uv.Pipe(self.loop) self.pipe.open(unix_socket.fileno()) self.assert_equal(self.pipe.fileno(), unix_socket.fileno())
def test_family(self): self.pipe = uv.Pipe(self.loop)
def test_no_pending_accept(self): self.pipe = uv.Pipe(self.loop)
def test_sockname(self): self.pipe = uv.Pipe(self.loop) self.pipe.bind(TEST_PIPE1)
def test_writable_readable(self): self.pipe = uv.Pipe(self.loop) self.assert_false(self.pipe.readable) self.assert_false(self.pipe.writable)
def on_connection(pipe_handle, status): client = uv.Pipe(pipe_handle.loop) pipe_handle.accept(client) client.start_read(on_read) pipe_handle.close()