Bug 1754025 [wpt PR 32729] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / tools / tryselect / test / test_task_configs.py
blob0a5ae93392da4c75be83e4bb6650c326e3bba69b
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
7 import inspect
8 from argparse import ArgumentParser
10 import mozunit
11 import pytest
12 import subprocess
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)
19 TASK_CONFIG_TESTS = {
20 "artifact": [
21 (["--no-artifact"], None),
22 (["--artifact"], {"use-artifact-builds": True}),
24 "chemspill-prio": [
25 ([], None),
26 (["--chemspill-prio"], {"chemspill-prio": {}}),
28 "env": [
29 ([], None),
30 (["--env", "foo=bar", "--env", "num=10"], {"env": {"foo": "bar", "num": "10"}}),
32 "path": [
33 ([], None),
35 ["dom/indexedDB"],
36 {"env": {"MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB"]}'}},
39 ["dom/indexedDB", "testing"],
41 "env": {
42 "MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB", "testing"]}'
46 (["invalid/path"], SystemExit),
48 "pernosco": [
49 ([], None),
51 "rebuild": [
52 ([], None),
53 (["--rebuild", "10"], {"rebuild": 10}),
54 (["--rebuild", "1"], SystemExit),
55 (["--rebuild", "21"], SystemExit),
57 "worker-overrides": [
58 ([], None),
60 ["--worker-override", "alias=worker/pool"],
61 {"worker-overrides": {"alias": "worker/pool"}},
65 "--worker-override",
66 "alias=worker/pool",
67 "--worker-override",
68 "alias=other/pool",
70 SystemExit,
73 ["--worker-suffix", "b-linux=-dev"],
74 {"worker-overrides": {"b-linux": "gecko-1/b-linux-dev"}},
78 "--worker-override",
79 "b-linux=worker/pool" "--worker-suffix",
80 "b-linux=-dev",
82 SystemExit,
88 @pytest.fixture
89 def config_patch_resolver(patch_resolver):
90 def inner(paths):
91 patch_resolver(
92 [], [{"flavor": "xpcshell", "srcdir_relpath": path} for path in paths]
95 return inner
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))
111 else:
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
118 @pytest.fixture
119 def patch_pernosco_email_check(monkeypatch):
120 def inner(val):
121 def fake_check_output(*args, **kwargs):
122 return val
124 monkeypatch.setattr(subprocess, "check_output", fake_check_output)
126 return inner
129 def test_pernosco(patch_pernosco_email_check):
130 patch_pernosco_email_check(
131 dedent(
133 user foobar@mozilla.com
134 hostname hg.mozilla.com
139 parser = ArgumentParser()
141 cfg = Pernosco()
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__":
148 mozunit.main()