1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
14 local_requirements
= {
15 b
"mozinfo": "testing/mozbase/mozinfo",
16 b
"mozlog": "testing/mozbase/mozlog",
17 b
"mozdebug": "testing/mozbase/mozdebug",
18 b
"marionette_driver": "testing/marionette/client/",
19 b
"mozprofile": "testing/mozbase/mozprofile",
20 b
"mozprocess": "testing/mozbase/mozprocess",
21 b
"mozcrash": "testing/mozbase/mozcrash",
22 b
"mozrunner": "testing/mozbase/mozrunner",
23 b
"mozleak": "testing/mozbase/mozleak",
24 b
"mozversion": "testing/mozbase/mozversion",
27 requirements_re
= re
.compile(rb
"(%s)[^\w]" % b
"|".join(local_requirements
.keys()))
30 class ReplaceRequirements(object):
31 def __init__(self
, top_src_path
, tox_path
):
32 self
.top_src_path
= top_src_path
33 self
.tox_path
= tox_path
38 deps
= self
.read_deps()
40 self
.replace_path(dep
)
42 def __exit__(self
, *args
, **kwargs
):
43 for path
, data
in self
.file_cache
.items():
44 with
open(path
, "wb") as f
:
49 parser
= configparser
.ConfigParser()
50 path
= os
.path
.join(self
.tox_path
, "tox.ini")
53 deps
= parser
.get("testenv", "deps")
54 dep_re
= re
.compile("(?:.*:\s*)?-r(.*)")
56 # This can break if we start using more features of tox
57 for dep
in deps
.splitlines():
60 rv
.append(m
.group(1).replace("{toxinidir}", self
.tox_path
))
63 def replace_path(self
, requirements_path
):
65 with
open(requirements_path
, "rb") as f
:
66 self
.file_cache
[requirements_path
] = f
.read()
69 m
= requirements_re
.match(line
)
74 path
= local_requirements
[key
]
77 % (os
.path
.join(self
.top_src_path
, path
).encode("utf8"),)
80 with
open(requirements_path
, "wb") as f
:
84 with
open(requirements_path
, "rb") as f
:
89 parser
= argparse
.ArgumentParser()
95 help="Don't run the tools unittests",
100 action
="store_false",
102 help="Don't run the wptrunner unittests",
105 "tox_kwargs", nargs
=argparse
.REMAINDER
, help="Arguments to pass through to tox"
110 def run(top_src_dir
, tools
=True, wptrunner
=True, tox_kwargs
=None, **kwargs
):
112 if tox_kwargs
is None:
116 os
.path
.join(top_src_dir
, "testing", "web-platform", "tests", "tools")
121 top_src_dir
, "testing", "web-platform", "tests", "tools", "wptrunner"
127 for tox_path
in tox_paths
:
128 with
ReplaceRequirements(top_src_dir
, tox_path
):
129 cmd
= ["tox"] + tox_kwargs
131 subprocess
.check_call(cmd
, cwd
=tox_path
)
132 except subprocess
.CalledProcessError
:
138 kwargs
= vars(get_parser().parse_args())
139 top_src_path
= os
.path
.abspath(os
.path
.join(here
, os
.pardir
, os
.pardir
))
140 return run(top_src_path
, **kwargs
)
143 if __name__
== "__main__":