def __enter__(self): self.port = get_free_port() self.server = HTTPServer(('127.0.0.1', self.port), self.RequestHandler) t = Thread(target=self.server.serve_forever) t.setDaemon(True) t.start() return self
def test_check_connect(port=None): assert check_connect('127.0.0.1', port=port, timeout=0.01) assert not check_connect('127.0.0.1', port=get_free_port(), timeout=0.01) def mock_socket(*args): raise socket.error pydu.request.socket.socket = mock_socket assert not check_connect('127.0.0.1', port=port, timeout=0.01)
def test_get_free_port(): port = get_free_port() assert isinstance(port, int) assert 65536 > port > 0