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/.
5 from __future__
import absolute_import
, print_function
, unicode_literals
8 from argparse
import ArgumentParser
13 from textwrap
import dedent
15 from tryselect
.task_config
import all_task_configs
, Pernosco
18 # task configs have a list of tests of the form (input, expected)
21 (["--no-artifact"], None),
22 (["--artifact"], {"use-artifact-builds": True}),
26 (["--chemspill-prio"], {"chemspill-prio": {}}),
30 (["--env", "foo=bar", "--env", "num=10"], {"env": {"foo": "bar", "num": "10"}}),
36 {"env": {"MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB"]}'}},
39 ["dom/indexedDB", "testing"],
42 "MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB", "testing"]}'
46 (["invalid/path"], SystemExit),
53 (["--rebuild", "10"], {"rebuild": 10}),
54 (["--rebuild", "1"], SystemExit),
55 (["--rebuild", "21"], SystemExit),
60 ["--worker-override", "alias=worker/pool"],
61 {"worker-overrides": {"alias": "worker/pool"}},
73 ["--worker-suffix", "b-linux=-dev"],
74 {"worker-overrides": {"b-linux": "gecko-1/b-linux-dev"}},
79 "b-linux=worker/pool" "--worker-suffix",
89 def config_patch_resolver(patch_resolver
):
92 [], [{"flavor": "xpcshell", "srcdir_relpath": path
} for path
in paths
]
98 def test_task_configs(config_patch_resolver
, task_config
, args
, expected
):
99 parser
= ArgumentParser()
101 cfg
= all_task_configs
[task_config
]()
102 cfg
.add_arguments(parser
)
104 if inspect
.isclass(expected
) and issubclass(expected
, BaseException
):
105 with pytest
.raises(expected
):
106 args
= parser
.parse_args(args
)
107 if task_config
== "path":
108 config_patch_resolver(**vars(args
))
110 cfg
.try_config(**vars(args
))
112 args
= parser
.parse_args(args
)
113 if task_config
== "path":
114 config_patch_resolver(**vars(args
))
115 assert cfg
.try_config(**vars(args
)) == expected
119 def patch_pernosco_email_check(monkeypatch
):
121 def fake_check_output(*args
, **kwargs
):
124 monkeypatch
.setattr(subprocess
, "check_output", fake_check_output
)
129 def test_pernosco(patch_pernosco_email_check
):
130 patch_pernosco_email_check(
133 user foobar@mozilla.com
134 hostname hg.mozilla.com
139 parser
= ArgumentParser()
142 cfg
.add_arguments(parser
)
143 args
= parser
.parse_args(["--pernosco"])
144 assert cfg
.try_config(**vars(args
)) == {"env": {"PERNOSCO": "1"}}
147 if __name__
== "__main__":