Bug 1855360 - Fix the skip-if syntax. a=bustage-fix
[gecko.git] / tools / tryselect / test / test_task_configs.py
blob4865a1bfca6bdd65a5ee0592125a79e145716610
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 import inspect
6 import subprocess
7 from argparse import ArgumentParser
8 from textwrap import dedent
10 import mozunit
11 import pytest
12 from tryselect.task_config import Pernosco, all_task_configs
14 # task configs have a list of tests of the form (input, expected)
15 TASK_CONFIG_TESTS = {
16 "artifact": [
17 (["--no-artifact"], None),
18 (["--artifact"], {"use-artifact-builds": True, "disable-pgo": True}),
20 "chemspill-prio": [
21 ([], None),
22 (["--chemspill-prio"], {"chemspill-prio": {}}),
24 "env": [
25 ([], None),
26 (["--env", "foo=bar", "--env", "num=10"], {"env": {"foo": "bar", "num": "10"}}),
28 "path": [
29 ([], None),
31 ["dom/indexedDB"],
32 {"env": {"MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB"]}'}},
35 ["dom/indexedDB", "testing"],
37 "env": {
38 "MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB", "testing"]}'
42 (["invalid/path"], SystemExit),
44 "pernosco": [
45 ([], None),
47 "rebuild": [
48 ([], None),
49 (["--rebuild", "10"], {"rebuild": 10}),
50 (["--rebuild", "1"], SystemExit),
51 (["--rebuild", "21"], SystemExit),
53 "worker-overrides": [
54 ([], None),
56 ["--worker-override", "alias=worker/pool"],
57 {"worker-overrides": {"alias": "worker/pool"}},
61 "--worker-override",
62 "alias=worker/pool",
63 "--worker-override",
64 "alias=other/pool",
66 SystemExit,
69 ["--worker-suffix", "b-linux=-dev"],
70 {"worker-overrides": {"b-linux": "gecko-1/b-linux-dev"}},
74 "--worker-override",
75 "b-linux=worker/pool" "--worker-suffix",
76 "b-linux=-dev",
78 SystemExit,
84 @pytest.fixture
85 def config_patch_resolver(patch_resolver):
86 def inner(paths):
87 patch_resolver(
88 [], [{"flavor": "xpcshell", "srcdir_relpath": path} for path in paths]
91 return inner
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))
107 else:
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
114 @pytest.fixture
115 def patch_pernosco_email_check(monkeypatch):
116 def inner(val):
117 def fake_check_output(*args, **kwargs):
118 return val
120 monkeypatch.setattr(subprocess, "check_output", fake_check_output)
122 return inner
125 def test_pernosco(patch_pernosco_email_check):
126 patch_pernosco_email_check(
127 dedent(
129 user foobar@mozilla.com
130 hostname hg.mozilla.com
135 parser = ArgumentParser()
137 cfg = Pernosco()
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__":
144 mozunit.main()