def test_normal_fail_message_too_big(self): tcp = Tcp("0.0.0.0", 0) with pytest.raises(ValueError) as exc: tcp.send(b"\x00" * 16777216) assert str(exc.value) == "Data to be sent over Direct TCP size " \ "16777216 exceeds the max length allowed " \ "16777215"
def server_tcp(request): server_func_name = 'server_' + request.node.name server_func = globals().get(server_func_name) if not server_func: raise Exception('Test must have defined %s to run the server thread' % server_func_name) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.bind(('127.0.0.1', 0)) sock.listen(1) server_thread = threading.Thread(target=server_func, args=(sock,)) server_thread.start() try: yield Tcp(*sock.getsockname()) finally: server_thread.join() finally: sock.close()
def test_invalid_host(self): tcp = Tcp("fake-host", 445) with pytest.raises(ValueError, match=re.escape("Failed to connect to 'fake-host:445': ")): tcp.connect()
def test_recv_fail_non_blocking(self): # ensure it doesn't loop when a non blocking error is raised tcp = Tcp("0.0.0.0", 0) with pytest.raises(socket.error) as err: tcp._recv(10) assert err.value.errno == errno.ENOTCONN
def test_send_fail_non_blocking(self): # ensure it doesn't loop when a non blocking error is raised tcp = Tcp("0.0.0.0", 0) with pytest.raises(socket.error) as err: tcp.send(b"\x01\x02\x03\x04")