Bug 1190349 - Update to latest wptrunner, a=testonly
authorJames Graham <james@hoppipolla.co.uk>
Mon, 03 Aug 2015 10:51:26 +0100
changeset 287552 e9e8affa4d6ffdf0c3538279ee0c3033dfaf0f52
parent 287551 9b96fb4b36525282e10aea7defc9f7f8869c1b3d
child 287553 ddff563c5c186821f40e84c89e2e4cb50046cb00
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1190349
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1190349 - Update to latest wptrunner, a=testonly
testing/web-platform/harness/wptrunner/environment.py
--- a/testing/web-platform/harness/wptrunner/environment.py
+++ b/testing/web-platform/harness/wptrunner/environment.py
@@ -75,63 +75,43 @@ def ssl_env(logger, **kwargs):
     ssl_env_cls = sslutils.environments[kwargs["ssl_type"]]
     return ssl_env_cls(logger, **get_ssl_kwargs(**kwargs))
 
 
 class TestEnvironmentError(Exception):
     pass
 
 
-class StaticHandler(object):
-    def __init__(self, path, format_args, content_type, **headers):
-        with open(path) as f:
-            self.data = f.read() % format_args
-
-        self.resp_headers = [("Content-Type", content_type)]
-        for k, v in headers.iteritems():
-            resp_headers.append((k.replace("_", "-"), v))
-
-        self.handler = serve.handlers.handler(self.handle_request)
-
-    def handle_request(self, request, response):
-        return self.resp_headers, self.data
-
-    def __call__(self, request, response):
-        rv = self.handler(request, response)
-        return rv
-
-
 class TestEnvironment(object):
     def __init__(self, test_paths, ssl_env, pause_after_test, debug_info, options):
         """Context manager that owns the test environment i.e. the http and
         websockets servers"""
         self.test_paths = test_paths
         self.ssl_env = ssl_env
         self.server = None
         self.config = None
         self.external_config = None
         self.pause_after_test = pause_after_test
         self.test_server_port = options.pop("test_server_port", True)
         self.debug_info = debug_info
         self.options = options if options is not None else {}
 
         self.cache_manager = multiprocessing.Manager()
-        self.routes = self.get_routes()
         self.stash = serve.stash.StashServer()
 
 
     def __enter__(self):
         self.stash.__enter__()
         self.ssl_env.__enter__()
         self.cache_manager.__enter__()
         self.setup_server_logging()
         self.config = self.load_config()
         serve.set_computed_defaults(self.config)
         self.external_config, self.servers = serve.start(self.config, self.ssl_env,
-                                                         self.routes)
+                                                         self.get_routes())
         if self.options.get("supports_debugger") and self.debug_info and self.debug_info.interactive:
             self.ignore_interrupts()
         return self
 
     def __exit__(self, exc_type, exc_val, exc_tb):
         self.process_interrupts()
         for scheme, servers in self.servers.iteritems():
             for port, server in servers:
@@ -190,50 +170,35 @@ class TestEnvironment(object):
             #Set as the default logger for wptserve
             serve.set_logger(server_logger)
             serve.logger = server_logger
         except Exception:
             # This happens if logging has already been set up for wptserve
             pass
 
     def get_routes(self):
-        routes = serve.default_routes()
+        route_builder = serve.RoutesBuilder()
+
         for path, format_args, content_type, route in [
                 ("testharness_runner.html", {}, "text/html", "/testharness_runner.html"),
                 (self.options.get("testharnessreport", "testharnessreport.js"),
                  {"output": self.pause_after_test}, "text/javascript",
                  "/resources/testharnessreport.js")]:
-            handler = StaticHandler(os.path.join(here, path), format_args, content_type)
-            routes.insert(0, (b"GET", str(route), handler))
-
-        for url, paths in self.test_paths.iteritems():
-            if url == "/":
-                continue
-
-            path = paths["tests_path"]
-            url = "/%s/" % url.strip("/")
+            path = os.path.normpath(os.path.join(here, path))
+            route_builder.add_static(path, format_args, content_type, route)
 
-            for (method,
-                 suffix,
-                 handler_cls) in [(b"*",
-                                   b"*.py",
-                                   serve.handlers.PythonScriptHandler),
-                                  (b"GET",
-                                   "*.asis",
-                                   serve.handlers.AsIsHandler),
-                                  (b"GET",
-                                   "*",
-                                   serve.handlers.FileHandler)]:
-                route = (method, b"%s%s" % (str(url), str(suffix)), handler_cls(path, url_base=url))
-                routes.insert(-3, route)
+        for url_base, paths in self.test_paths.iteritems():
+            if url_base == "/":
+                continue
+            route_builder.add_mount_point(url_base, paths["tests_path"])
 
         if "/" not in self.test_paths:
-            routes = routes[:-3]
+            del route_builder.mountpoint_routes["/"]
 
-        return routes
+        return route_builder.get_routes()
 
     def ensure_started(self):
         # Pause for a while to ensure that the server has a chance to start
         time.sleep(2)
         for scheme, servers in self.servers.iteritems():
             for port, server in servers:
                 if self.test_server_port:
                     s = socket.socket()