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
build / chromeos / generate_skylab_tast_filter_test.py [blame]
#!/usr/bin/env vpython3
#
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
from unittest import mock
import generate_skylab_tast_filter
TAST_CONTROL = '''
# Ignore comments
tast_disabled_tests_from_chrome_all = [
"example.all.test1",
]
tast_disabled_tests_from_chrome_m100 = [
"example.m100.test1",
]
tast_disabled_tests_from_lacros_all = []
'''
TAST_EXPR = '"group:mainline" && "dep:chrome" && !informational'
REQUIRED_ARGS = ['script', 'generate-filter', '--output', 'output.filter']
class GenerateSkylabTastFilterTest(unittest.TestCase):
def testTastExpr(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + ['--tast-expr', TAST_EXPR]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
self.assertEqual(filter_dict['default'], '(%s)' % TAST_EXPR)
def testTastExprAndDisableTests(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + [
'--tast-expr', TAST_EXPR, '--disabled-tests', 'disabled.test1',
'--disabled-tests', 'disabled.test2'
]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
self.assertEqual(
filter_dict['default'],
'(%s && !"name:disabled.test1" && !"name:disabled.test2")' %
TAST_EXPR)
def testEnableTests(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + [
'--enabled-tests', 'enabled.test1', '--enabled-tests', 'enabled.test2'
]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
self.assertEqual(filter_dict['default'],
'("name:enabled.test1" || "name:enabled.test2")')
def testTastControlWithTastExpr(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + [
'--tast-expr',
TAST_EXPR,
'--tast-control',
'mocked_input',
]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
self.assertEqual(filter_dict['default'], '(%s)' % TAST_EXPR)
self.assertEqual(filter_dict['tast_disabled_tests_from_chrome_m100'],
'(%s && !"name:example.m100.test1")' % TAST_EXPR)
def testTastControlWithTastExprAndDisabledTests(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + [
'--tast-expr', TAST_EXPR, '--tast-control', 'mocked_input',
'--disabled-tests', 'disabled.test1', '--disabled-tests',
'disabled.test2'
]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
self.assertEqual(
filter_dict['default'],
'("group:mainline" && "dep:chrome" && !informational && !'\
'"name:disabled.test1" && !"name:disabled.test2")'
)
# The list from a set is indeterminent
self.assertIn('"group:mainline" && "dep:chrome" && !informational',
filter_dict['tast_disabled_tests_from_chrome_m100'])
self.assertIn('&& !"name:disabled.test1"',
filter_dict['tast_disabled_tests_from_chrome_m100'])
self.assertIn('&& !"name:disabled.test2"',
filter_dict['tast_disabled_tests_from_chrome_m100'])
self.assertIn('&& !"name:example.m100.test1"',
filter_dict['tast_disabled_tests_from_chrome_m100'])
def testTastControlWithTastExprAndEnabledTests(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + [
'--tast-expr', TAST_EXPR, '--tast-control', 'mocked_input',
'--enabled-tests', 'enabled.test1', '--enabled-tests', 'enabled.test2'
]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
self.assertEqual(
filter_dict['default'],
'("group:mainline" && "dep:chrome" && !informational && '\
'("name:enabled.test1" || "name:enabled.test2"))'
)
self.assertEqual(
filter_dict['tast_disabled_tests_from_chrome_m100'],
'("group:mainline" && "dep:chrome" && !informational && '\
'!"name:example.m100.test1" && ("name:enabled.test1" '\
'|| "name:enabled.test2"))'
)
def testTastControlWithEnabledTests(self):
file_mock = mock.mock_open(read_data=TAST_CONTROL)
args = REQUIRED_ARGS + [
'--tast-control',
'mocked_input',
'--enabled-tests',
'enabled.test1',
'--enabled-tests',
'enabled.test2',
]
with mock.patch('sys.argv', args),\
mock.patch('builtins.open', file_mock),\
mock.patch('os.chmod'),\
mock.patch("json.dump", mock.MagicMock()) as dump:
generate_skylab_tast_filter.main()
filter_dict = dump.call_args[0][0]
# Should not include 'all' collection from TAST_CONTROL since that would
# need to be passed in the --disabled-tests to be included
self.assertEqual(filter_dict['default'],
'("name:enabled.test1" || "name:enabled.test2")')
self.assertEqual(
filter_dict['tast_disabled_tests_from_chrome_m100'],
'(!"name:example.m100.test1" && '\
'("name:enabled.test1" || "name:enabled.test2"))'
)
if __name__ == '__main__':
unittest.main()