def test_server_constructor_socket(): us = '/run/sock' server = HTTPServer(sockfile=us) assert server.unix_socket == us server.port = 70 assert server.port is 70 with pytest.raises(KeyError): server.unix_socket
def test_random_port(): # assume there will be a free port we could bind to in range [10000,11000) for x in range(10000, 11000): port = HTTPServer.get_random_port((x, x+1)) if port is not None: assert port == x break
def test_bad_port_range(): # assume there will be a free port we could bind to in range [10000,11000) with pytest.raises(Exception): HTTPServer.get_random_port((10001, 10000))