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/.
7 from argparse
import ArgumentParser
8 from textwrap
import dedent
12 from tryselect
.task_config
import Pernosco
, all_task_configs
14 # task configs have a list of tests of the form (input, expected)
17 (["--no-artifact"], None),
18 (["--artifact"], {"use-artifact-builds": True, "disable-pgo": True}),
22 (["--chemspill-prio"], {"chemspill-prio": {}}),
26 (["--env", "foo=bar", "--env", "num=10"], {"env": {"foo": "bar", "num": "10"}}),
32 {"env": {"MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB"]}'}},
35 ["dom/indexedDB", "testing"],
38 "MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB", "testing"]}'
42 (["invalid/path"], SystemExit),
49 (["--rebuild", "10"], {"rebuild": 10}),
50 (["--rebuild", "1"], SystemExit),
51 (["--rebuild", "21"], SystemExit),
56 ["--worker-override", "alias=worker/pool"],
57 {"worker-overrides": {"alias": "worker/pool"}},
69 ["--worker-suffix", "b-linux=-dev"],
70 {"worker-overrides": {"b-linux": "gecko-1/b-linux-dev"}},
75 "b-linux=worker/pool" "--worker-suffix",
85 def config_patch_resolver(patch_resolver
):
88 [], [{"flavor": "xpcshell", "srcdir_relpath": path
} for path
in paths
]
94 def test_task_configs(config_patch_resolver
, task_config
, args
, expected
):
95 parser
= ArgumentParser()
97 cfg
= all_task_configs
[task_config
]()
98 cfg
.add_arguments(parser
)
100 if inspect
.isclass(expected
) and issubclass(expected
, BaseException
):
101 with pytest
.raises(expected
):
102 args
= parser
.parse_args(args
)
103 if task_config
== "path":
104 config_patch_resolver(**vars(args
))
106 cfg
.try_config(**vars(args
))
108 args
= parser
.parse_args(args
)
109 if task_config
== "path":
110 config_patch_resolver(**vars(args
))
111 assert cfg
.try_config(**vars(args
)) == expected
115 def patch_pernosco_email_check(monkeypatch
):
117 def fake_check_output(*args
, **kwargs
):
120 monkeypatch
.setattr(subprocess
, "check_output", fake_check_output
)
125 def test_pernosco(patch_pernosco_email_check
):
126 patch_pernosco_email_check(
129 user foobar@mozilla.com
130 hostname hg.mozilla.com
135 parser
= ArgumentParser()
138 cfg
.add_arguments(parser
)
139 args
= parser
.parse_args(["--pernosco"])
140 assert cfg
.try_config(**vars(args
)) == {"env": {"PERNOSCO": "1"}}
143 if __name__
== "__main__":