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/.
13 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
15 local_requirements
= {
16 b
"mozinfo": "testing/mozbase/mozinfo",
17 b
"mozlog": "testing/mozbase/mozlog",
18 b
"mozdebug": "testing/mozbase/mozdebug",
19 b
"marionette_driver": "testing/marionette/client/",
20 b
"mozprofile": "testing/mozbase/mozprofile",
21 b
"mozprocess": "testing/mozbase/mozprocess",
22 b
"mozcrash": "testing/mozbase/mozcrash",
23 b
"mozrunner": "testing/mozbase/mozrunner",
24 b
"mozleak": "testing/mozbase/mozleak",
25 b
"mozversion": "testing/mozbase/mozversion",
28 requirements_re
= re
.compile(rb
"(%s)[^\w]" % b
"|".join(local_requirements
.keys()))
31 class ReplaceRequirements(object):
32 def __init__(self
, top_src_path
, tox_path
):
33 self
.top_src_path
= top_src_path
34 self
.tox_path
= tox_path
39 deps
= self
.read_deps()
41 self
.replace_path(dep
)
43 def __exit__(self
, *args
, **kwargs
):
44 for path
, data
in self
.file_cache
.items():
45 with
open(path
, "wb") as f
:
50 parser
= configparser
.ConfigParser()
51 path
= os
.path
.join(self
.tox_path
, "tox.ini")
54 deps
= parser
.get("testenv", "deps")
55 dep_re
= re
.compile("(?:.*:\s*)?-r(.*)")
57 # This can break if we start using more features of tox
58 for dep
in deps
.splitlines():
61 rv
.append(m
.group(1).replace("{toxinidir}", self
.tox_path
))
64 def replace_path(self
, requirements_path
):
66 with
open(requirements_path
, "rb") as f
:
67 self
.file_cache
[requirements_path
] = f
.read()
70 m
= requirements_re
.match(line
)
75 path
= local_requirements
[key
]
78 % (os
.path
.join(self
.top_src_path
, path
).encode("utf8"),)
81 with
open(requirements_path
, "wb") as f
:
85 with
open(requirements_path
, "rb") as f
:
90 parser
= argparse
.ArgumentParser()
96 help="Don't run the tools unittests",
101 action
="store_false",
103 help="Don't run the wptrunner unittests",
106 "tox_kwargs", nargs
=argparse
.REMAINDER
, help="Arguments to pass through to tox"
111 def run(top_src_dir
, tools
=True, wptrunner
=True, tox_kwargs
=None, **kwargs
):
113 if tox_kwargs
is None:
117 os
.path
.join(top_src_dir
, "testing", "web-platform", "tests", "tools")
122 top_src_dir
, "testing", "web-platform", "tests", "tools", "wptrunner"
128 for tox_path
in tox_paths
:
129 with
ReplaceRequirements(top_src_dir
, tox_path
):
130 cmd
= ["tox"] + tox_kwargs
132 subprocess
.check_call(cmd
, cwd
=tox_path
)
133 except subprocess
.CalledProcessError
:
139 kwargs
= vars(get_parser().parse_args())
140 top_src_path
= os
.path
.abspath(os
.path
.join(here
, os
.pardir
, os
.pardir
))
141 return run(top_src_path
, **kwargs
)
144 if __name__
== "__main__":