From b3bda54df8a89904fb22f55558ec9a43e56ade47 Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Thu, 15 Dec 2016 11:02:59 -0800 Subject: [PATCH] Modify HTTP/2 test server to display a list of available test cases and accept non-positional arguments. --- test/http2_test/http2_test_server.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/http2_test/http2_test_server.py b/test/http2_test/http2_test_server.py index 1549d6da61c..fc88410f69f 100644 --- a/test/http2_test/http2_test_server.py +++ b/test/http2_test/http2_test_server.py @@ -45,15 +45,18 @@ class H2Factory(twisted.internet.protocol.Factory): else: return t().get_base_server() -if __name__ == "__main__": - logging.basicConfig(format = "%(levelname) -10s %(asctime)s %(module)s:%(lineno)s | %(message)s", level=logging.INFO) +if __name__ == '__main__': + logging.basicConfig( + format='%(levelname) -10s %(asctime)s %(module)s:%(lineno)s | %(message)s', + level=logging.INFO) parser = argparse.ArgumentParser() - parser.add_argument("test") - parser.add_argument("port") + parser.add_argument('--test_case', choices=sorted(_TEST_CASE_MAPPING.keys()), + help='test case to run', required=True) + parser.add_argument('--port', type=int, default=8080, + help='port to run the server (default: 8080)') args = parser.parse_args() - if args.test not in _TEST_CASE_MAPPING.keys(): - logging.error('unknown test: %s' % args.test) - else: - endpoint = twisted.internet.endpoints.TCP4ServerEndpoint(twisted.internet.reactor, int(args.port), backlog=128) - endpoint.listen(H2Factory(args.test)) - twisted.internet.reactor.run() + logging.info('Running test case %s on port %d' % (args.test_case, args.port)) + endpoint = twisted.internet.endpoints.TCP4ServerEndpoint( + twisted.internet.reactor, args.port, backlog=128) + endpoint.listen(H2Factory(args.test_case)) + twisted.internet.reactor.run()