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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# 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/.
import os
import mozunit
import pytest
from tryselect.tasks import (
cache_key,
filter_tasks_by_paths,
filter_tasks_by_worker_type,
resolve_tests_by_suite,
)
class task:
def __init__(self, workerType):
self.workerType = workerType
@property
def task(self):
return {"workerType": self.workerType}
@pytest.mark.parametrize(
"tasks, params, expected",
(
pytest.param(
{
"foobar/xpcshell-1": task("t-unittest-314"),
"foobar/mochitest": task("t-unittest-157"),
"foobar/xpcshell-gpu": task("t-unittest-314-gpu"),
"foobar/xpcshell": task("t-unittest-314"),
},
{"try_task_config": {"worker-types": ["t-unittest-314"]}},
[
"foobar/xpcshell-1",
"foobar/xpcshell",
],
id="single worker",
),
pytest.param(
{
"foobar/xpcshell-1": task("t-unittest-314"),
"foobar/mochitest": task("t-unittest-157"),
"foobar/xpcshell-gpu": task("t-unittest-314-gpu"),
"foobar/xpcshell": task("t-unittest-314"),
},
{
"try_task_config": {
"worker-types": ["t-unittest-314", "t-unittest-314-gpu"]
}
},
[
"foobar/xpcshell-1",
"foobar/xpcshell-gpu",
"foobar/xpcshell",
],
id="multiple workers worker",
),
pytest.param(
{
"foobar/xpcshell-1": task("t-unittest-314"),
"foobar/mochitest": task("t-unittest-157"),
"foobar/xpcshell-gpu": task("t-unittest-314-gpu"),
"foobar/xpcshell": task("t-unittest-314"),
},
{"try_task_config": {"worker-types": ["t-unittest-157"]}},
[
"foobar/mochitest",
],
id="single task",
),
pytest.param(
{
"foobar/xpcshell-1": task("t-unittest-314"),
"foobar/mochitest": task("t-unittest-157"),
"foobar/xpcshell-gpu": task("t-unittest-314-gpu"),
"foobar/xpcshell": task("t-unittest-314"),
},
{"try_task_config": {"worker-types": []}},
[
"foobar/xpcshell-1",
"foobar/mochitest",
"foobar/xpcshell-gpu",
"foobar/xpcshell",
],
id="no worker",
),
pytest.param(
{
"foobar/xpcshell-1": task("t-unittest-314"),
"foobar/mochitest": task("t-unittest-157"),
"foobar/xpcshell-gpu": task("t-unittest-314-gpu"),
"foobar/xpcshell": task("t-unittest-314"),
},
{"try_task_config": {"worker-types": ["fake-worker"]}},
[],
id="invalid worker",
),
),
)
def test_filter_tasks_by_worker_type(patch_resolver, tasks, params, expected):
assert list(filter_tasks_by_worker_type(tasks, params)) == expected
def test_filter_tasks_by_paths(patch_resolver):
tasks = {"foobar/xpcshell-1": {}, "foobar/mochitest": {}, "foobar/xpcshell": {}}
patch_resolver(["xpcshell"], {})
assert list(filter_tasks_by_paths(tasks, "dummy")) == []
patch_resolver([], [{"flavor": "xpcshell"}])
assert list(filter_tasks_by_paths(tasks, "dummy")) == [
"foobar/xpcshell-1",
"foobar/xpcshell",
]
@pytest.mark.parametrize(
"input, tests, expected",
(
pytest.param(
["xpcshell.js"],
[{"flavor": "xpcshell", "srcdir_relpath": "xpcshell.js"}],
{"xpcshell": ["xpcshell.js"]},
id="single test",
),
pytest.param(
["xpcshell.ini"],
[
{
"flavor": "xpcshell",
"srcdir_relpath": "xpcshell.js",
"manifest_relpath": "xpcshell.ini",
},
],
{"xpcshell": ["xpcshell.ini"]},
id="single manifest",
),
pytest.param(
["xpcshell.js", "mochitest.js"],
[
{"flavor": "xpcshell", "srcdir_relpath": "xpcshell.js"},
{"flavor": "mochitest", "srcdir_relpath": "mochitest.js"},
],
{
"xpcshell": ["xpcshell.js"],
"mochitest-plain": ["mochitest.js"],
},
id="two tests",
),
pytest.param(
["test/xpcshell.ini"],
[
{
"flavor": "xpcshell",
"srcdir_relpath": "test/xpcshell.js",
"manifest_relpath": os.path.join("test", "xpcshell.ini"),
},
],
{"xpcshell": ["test/xpcshell.ini"]},
id="mismatched path separators",
),
),
)
def test_resolve_tests_by_suite(patch_resolver, input, tests, expected):
patch_resolver([], tests)
assert resolve_tests_by_suite(input) == expected
@pytest.mark.parametrize(
"attr,params,disable_target_task_filter,expected",
(
("target_task_set", None, False, "target_task_set"),
("target_task_set", {"project": "autoland"}, False, "target_task_set"),
("target_task_set", {"project": "mozilla-central"}, False, "target_task_set"),
("target_task_set", None, True, "target_task_set-uncommon"),
("full_task_set", {"project": "pine"}, False, "full_task_set-pine"),
("full_task_set", None, True, "full_task_set"),
),
)
def test_cache_key(attr, params, disable_target_task_filter, expected):
assert cache_key(attr, params, disable_target_task_filter) == expected
if __name__ == "__main__":
mozunit.main()
|