def __init__(self, port): """Create a MockHTTP server listening on localhost at the given port.""" self.server_address = ('localhost', port) self.finish_serving = threading.Event() self.finished_serving = threading.Event() tree = Tree() mock_root = MockRoot(self) tree.mount(mock_root, '/') self.server = CherryPyWSGIServer( self.server_address, tree, server_name='localhost', numthreads=1) self.thread = threading.Thread( target=_server_thread, kwargs={'server': self.server, 'finished_serving': self.finished_serving}) self.thread.start() while not self.server.ready: time.sleep(0.1) self.last_failure = None self.expected = defaultdict(dict) self.expected_by_name = {}
def __init__(self, port, shutdown_on_verify=True): """Create a MockHTTP server listening on localhost at the given port.""" self.server_address = ('localhost', port) self.shutdown_on_verify = shutdown_on_verify self.finish_serving = threading.Event() self.finished_serving = threading.Event() tree = Tree() mock_root = MockRoot(self) tree.mount(mock_root, '/') self.server = CherryPyWSGIServer( self.server_address, tree, server_name='localhost', numthreads=1) self.thread = threading.Thread( target=_server_thread, kwargs={'server': self.server, 'finished_serving': self.finished_serving}) self.thread.start() log.debug("Starting %s", self) while not self.server.ready: time.sleep(0.1) log.debug("Started %s", self) self.reset()