def log_request(self, code, size=None): # For present purposes, we don't want the request splattered onto # stderr, as it would upset devs watching the test run pass def log_error(self, format, *args): # Suppress error output as well pass class Server(HTTPServer): # This pernicious flag is on by default in HTTPServer. But proper # operation of freeport() absolutely depends on it being off. allow_reuse_address = False if __name__ == "__main__": # Instantiate a Server(TestHTTPRequestHandler) on the first free port # in the specified port range. Doing this inline is better than in a # daemon thread: if it blows up here, we'll get a traceback. If it blew up # in some other thread, the traceback would get eaten and we'd run the # subject test program anyway. httpd, port = freeport(xrange(8000, 8020), lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler)) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. os.environ["PORT"] = str(port) debug("$PORT = %s", port) sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), *sys.argv[1:]))
def hello(self, who): # LLXMLRPCListener expects a dict return. return {"hi_there": "Hello, %s!" % who} def getdict(self): return dict(nested_dict=dict(a=17, b=5)) def log_request(self, code, size=None): # For present purposes, we don't want the request splattered onto # stderr, as it would upset devs watching the test run pass def log_error(self, format, *args): # Suppress error output as well pass if __name__ == "__main__": # Instantiate a TestServer on the first free port in the specified port # range. Doing this inline is better than in a daemon thread: if it blows # up here, we'll get a traceback. If it blew up in some other thread, the # traceback would get eaten and we'd run the subject test program anyway. xmlrpcd, port = freeport(xrange(8000, 8020), lambda port: TestServer(('127.0.0.1', port))) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. os.environ["PORT"] = str(port) sys.exit(run(server=Thread(name="xmlrpc", target=xmlrpcd.serve_forever), *sys.argv[1:]))
def log_request(self, code, size=None): # For present purposes, we don't want the request splattered onto # stderr, as it would upset devs watching the test run pass def log_error(self, format, *args): # Suppress error output as well pass if __name__ == "__main__": # function to make a server with specified port make_server = lambda port: TestServer(('127.0.0.1', port)) if not sys.platform.startswith("win"): # Instantiate a TestServer on a port chosen by the runtime. xmlrpcd = make_server(0) else: # "Then there's Windows" # Instantiate a TestServer on the first free port in the specified # port range. xmlrpcd, port = freeport(xrange(8000, 8020), make_server) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. os.environ["PORT"] = str(xmlrpcd.server_port) sys.exit(run(server_inst=xmlrpcd, *sys.argv[1:]))
path_search = False options, args = getopt.getopt(sys.argv[1:], "V", ["valgrind"]) for option, value in options: if option == "-V" or option == "--valgrind": do_valgrind = True # function to make a server with specified port make_server = lambda port: Server( ('127.0.0.1', port), TestHTTPRequestHandler) if not sys.platform.startswith("win"): # Instantiate a Server(TestHTTPRequestHandler) on a port chosen by the # runtime. httpd = make_server(0) else: # "Then there's Windows" # Instantiate a Server(TestHTTPRequestHandler) on the first free port # in the specified port range. httpd, port = freeport(range(8000, 8020), make_server) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. os.environ["LL_TEST_PORT"] = str(httpd.server_port) debug("$LL_TEST_PORT = %s", httpd.server_port) if do_valgrind: args = ["valgrind", "--log-file=./valgrind.log"] + args path_search = True sys.exit(run(server_inst=httpd, use_path=path_search, *args))
return {"hi_there": "Hello, %s!" % who} def getdict(self): return dict(nested_dict=dict(a=17, b=5)) def log_request(self, code, size=None): # For present purposes, we don't want the request splattered onto # stderr, as it would upset devs watching the test run pass def log_error(self, format, *args): # Suppress error output as well pass if __name__ == "__main__": # Instantiate a TestServer on the first free port in the specified port # range. Doing this inline is better than in a daemon thread: if it blows # up here, we'll get a traceback. If it blew up in some other thread, the # traceback would get eaten and we'd run the subject test program anyway. xmlrpcd, port = freeport(xrange(8000, 8020), lambda port: TestServer( ('127.0.0.1', port))) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. os.environ["PORT"] = str(port) sys.exit( run(server=Thread(name="xmlrpc", target=xmlrpcd.serve_forever), *sys.argv[1:]))