1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function, unicode_literals
import inspect
from argparse import ArgumentParser
import mozunit
import pytest
import subprocess
from textwrap import dedent
from tryselect.task_config import all_task_configs, Pernosco
# task configs have a list of tests of the form (input, expected)
TASK_CONFIG_TESTS = {
"artifact": [
(["--no-artifact"], None),
(["--artifact"], {"use-artifact-builds": True}),
],
"chemspill-prio": [
([], None),
(["--chemspill-prio"], {"chemspill-prio": {}}),
],
"env": [
([], None),
(["--env", "foo=bar", "--env", "num=10"], {"env": {"foo": "bar", "num": "10"}}),
],
"path": [
([], None),
(
["dom/indexedDB"],
{"env": {"MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB"]}'}},
),
(
["dom/indexedDB", "testing"],
{
"env": {
"MOZHARNESS_TEST_PATHS": '{"xpcshell": ["dom/indexedDB", "testing"]}'
}
},
),
(["invalid/path"], SystemExit),
],
"pernosco": [
([], None),
],
"rebuild": [
([], None),
(["--rebuild", "10"], {"rebuild": 10}),
(["--rebuild", "1"], SystemExit),
(["--rebuild", "21"], SystemExit),
],
"worker-overrides": [
([], None),
(
["--worker-override", "alias=worker/pool"],
{"worker-overrides": {"alias": "worker/pool"}},
),
(
[
"--worker-override",
"alias=worker/pool",
"--worker-override",
"alias=other/pool",
],
SystemExit,
),
(
["--worker-suffix", "b-linux=-dev"],
{"worker-overrides": {"b-linux": "gecko-1/b-linux-dev"}},
),
(
[
"--worker-override",
"b-linux=worker/pool" "--worker-suffix",
"b-linux=-dev",
],
SystemExit,
),
],
}
@pytest.fixture
def config_patch_resolver(patch_resolver):
def inner(paths):
patch_resolver(
[], [{"flavor": "xpcshell", "srcdir_relpath": path} for path in paths]
)
return inner
def test_task_configs(config_patch_resolver, task_config, args, expected):
parser = ArgumentParser()
cfg = all_task_configs[task_config]()
cfg.add_arguments(parser)
if inspect.isclass(expected) and issubclass(expected, BaseException):
with pytest.raises(expected):
args = parser.parse_args(args)
if task_config == "path":
config_patch_resolver(**vars(args))
cfg.try_config(**vars(args))
else:
args = parser.parse_args(args)
if task_config == "path":
config_patch_resolver(**vars(args))
assert cfg.try_config(**vars(args)) == expected
@pytest.fixture
def patch_pernosco_email_check(monkeypatch):
def inner(val):
def fake_check_output(*args, **kwargs):
return val
monkeypatch.setattr(subprocess, "check_output", fake_check_output)
return inner
def test_pernosco(patch_pernosco_email_check):
patch_pernosco_email_check(
dedent(
"""
user foobar@mozilla.com
hostname hg.mozilla.com
"""
)
)
parser = ArgumentParser()
cfg = Pernosco()
cfg.add_arguments(parser)
args = parser.parse_args(["--pernosco"])
assert cfg.try_config(**vars(args)) == {"env": {"PERNOSCO": "1"}}
if __name__ == "__main__":
mozunit.main()
|