Bug 1586807 - Make pseudoclass locking work with Fission. r=pbro
[gecko.git] / testing / web-platform / unittestrunner.py
blobe8c16506e4ff36e60400d71dc40cdd1b8faddc05
1 import ConfigParser
2 import argparse
3 import os
4 import re
5 import subprocess
6 import sys
9 here = os.path.abspath(os.path.dirname(__file__))
11 local_requirements = {
12 "mozinfo": "testing/mozbase/mozinfo",
13 "mozlog": "testing/mozbase/mozlog",
14 "mozdebug": "testing/mozbase/mozdebug",
15 "marionette_driver": "testing/marionette/client/",
16 "mozprofile": "testing/mozbase/mozprofile",
17 "mozprocess": "testing/mozbase/mozprocess",
18 "mozcrash": "testing/mozbase/mozcrash",
19 "mozrunner": "testing/mozbase/mozrunner",
20 "mozleak": "testing/mozbase/mozleak",
21 "mozversion": "testing/mozbase/mozversion",
24 requirements_re = re.compile(r"(%s)[^\w]" % "|".join(local_requirements.keys()))
27 class ReplaceRequirements(object):
28 def __init__(self, top_src_path, tox_path):
29 self.top_src_path = top_src_path
30 self.tox_path = tox_path
31 self.file_cache = {}
33 def __enter__(self):
34 self.file_cache = {}
35 deps = self.read_deps()
36 for dep in deps:
37 self.replace_path(dep)
39 def __exit__(self, *args, **kwargs):
40 for path, data in self.file_cache.iteritems():
41 with open(path, "wb") as f:
42 f.write(data)
44 def read_deps(self):
45 rv = []
46 parser = ConfigParser.ConfigParser()
47 path = os.path.join(self.tox_path, "tox.ini")
48 with open(path) as f:
49 parser.readfp(f)
50 deps = parser.get("testenv", "deps")
51 dep_re = re.compile("(?:.*:\s*)?-r(.*)")
53 # This can break if we start using more features of tox
54 for dep in deps.splitlines():
55 m = dep_re.match(dep)
56 if m:
57 rv.append(m.group(1).replace("{toxinidir}", self.tox_path))
58 return rv
60 def replace_path(self, requirements_path):
61 lines = []
62 with open(requirements_path, "rb") as f:
63 self.file_cache[requirements_path] = f.read()
64 f.seek(0)
65 for line in f:
66 m = requirements_re.match(line)
67 if not m:
68 lines.append(line)
69 else:
70 key = m.group(1)
71 path = local_requirements[key]
72 lines.append("-e %s\n" % (os.path.join(self.top_src_path, path),))
74 with open(requirements_path, "wb") as f:
75 for line in lines:
76 f.write(line.encode("utf8"))
78 with open(requirements_path, "rb") as f:
79 print(f.read())
82 def get_parser():
83 parser = argparse.ArgumentParser()
84 parser.add_argument("--no-tools", dest="tools", action="store_false",
85 default=True, help="Don't run the tools unittests")
86 parser.add_argument("--no-wptrunner", dest="wptrunner", action="store_false",
87 default=True, help="Don't run the wptrunner unittests")
88 parser.add_argument("tox_kwargs", nargs=argparse.REMAINDER,
89 help="Arguments to pass through to tox")
90 return parser
93 def run(top_src_dir, tools=True, wptrunner=True, tox_kwargs=None, **kwargs):
94 tox_paths = []
95 if tox_kwargs is None:
96 tox_kwargs = []
97 if tools:
98 tox_paths.append(os.path.join(top_src_dir,
99 "testing",
100 "web-platform",
101 "tests",
102 "tools"))
103 if wptrunner:
104 tox_paths.append(os.path.join(top_src_dir,
105 "testing",
106 "web-platform",
107 "tests",
108 "tools",
109 "wptrunner"))
111 success = True
113 for tox_path in tox_paths:
114 with ReplaceRequirements(top_src_dir, tox_path):
115 cmd = ["tox"] + tox_kwargs
116 try:
117 subprocess.check_call(cmd, cwd=tox_path)
118 except subprocess.CalledProcessError:
119 success = False
120 return success
123 def main():
124 kwargs = vars(get_parser().parse_args())
125 top_src_path = os.path.abspath(os.path.join(here, os.pardir, os.pardir))
126 return run(top_src_path, **kwargs)
129 if __name__ == "__main__":
130 if not main():
131 sys.exit(1)