forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtry_flag_unittest.py
180 lines (160 loc) · 6.93 KB
/
try_flag_unittest.py
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
# Copyright 2017 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 blinkpy.common.host_mock import MockHost
from blinkpy.common.net.git_cl import BuildStatus
from blinkpy.common.net.git_cl_mock import MockGitCL
from blinkpy.common.net.results_fetcher import Build
from blinkpy.common.net.web_test_results import WebTestResults
from blinkpy.common.path_finder import PathFinder
from blinkpy.web_tests.try_flag import TryFlag
class TryFlagTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
self.linux_build = Build('linux-rel', 100)
self.mac_build = Build('mac-rel', 101)
self.win_build = Build('win7-rel', 102)
self.mock_try_results = {
self.linux_build: BuildStatus.SUCCESS,
self.win_build: BuildStatus.SUCCESS,
self.mac_build: BuildStatus.SUCCESS
}
super(TryFlagTest, self).__init__(*args, **kwargs)
def _run_trigger_test(self, regenerate):
host = MockHost()
git = host.git()
git_cl = MockGitCL(host)
finder = PathFinder(host.filesystem)
flag_file = finder.path_from_web_tests(
'additional-driver-flag.setting')
flag_expectations_file = finder.path_from_web_tests(
'FlagExpectations', 'foo')
cmd = ['trigger', '--flag=--foo']
if regenerate:
cmd.append('--regenerate')
TryFlag(cmd, host, git_cl).run()
expected_added_paths = {flag_file}
expected_commits = [[
'Flag try job: force --foo for run_web_tests.py.'
]]
if regenerate:
expected_added_paths.add(flag_expectations_file)
expected_commits.append(
['Flag try job: clear expectations for --foo.'])
self.assertEqual(git.added_paths, expected_added_paths)
self.assertEqual(git.local_commits(), expected_commits)
self.assertEqual(git_cl.calls, [[
'git', 'cl', 'upload', '--bypass-hooks', '-f', '-m',
'Flag try job for --foo.'
], [
'git', 'cl', 'try', '-B', 'luci.chromium.try', '-b', 'linux-rel'
], [
'git', 'cl', 'try', '-B', 'luci.chromium.try', '-b', 'mac-rel'
], ['git', 'cl', 'try', '-B', 'luci.chromium.try', '-b', 'win7-rel']])
def test_trigger(self):
self._run_trigger_test(regenerate=False)
self._run_trigger_test(regenerate=True)
def _setup_mock_results(self, results_fetcher):
results_fetcher.set_results(
self.linux_build,
WebTestResults.from_json(
{
'tests': {
'something': {
'fail-everywhere.html': {
'expected': 'FAIL',
'actual': 'FAIL',
'is_unexpected': True
},
'fail-win-and-linux.html': {
'expected': 'FAIL',
'actual': 'FAIL',
'is_unexpected': True
}
}
}
},
step_name='blink_web_tests'))
results_fetcher.set_results(
self.win_build,
WebTestResults.from_json(
{
'tests': {
'something': {
'fail-everywhere.html': {
'expected': 'FAIL',
'actual': 'FAIL',
'is_unexpected': True
},
'fail-win-and-linux.html': {
'expected': 'FAIL',
'actual': 'FAIL',
'is_unexpected': True
}
}
}
},
step_name='blink_web_tests'))
results_fetcher.set_results(
self.mac_build,
WebTestResults.from_json(
{
'tests': {
'something': {
'pass-unexpectedly-mac.html': {
'expected': 'FAIL',
'actual': 'PASS',
'is_unexpected': True
},
'fail-everywhere.html': {
'expected': 'FAIL',
'actual': 'FAIL',
'is_unexpected': True
}
}
}
},
step_name='blink_web_tests'))
def test_update(self):
host = MockHost()
filesystem = host.filesystem
finder = PathFinder(filesystem)
flag_expectations_file = finder.path_from_web_tests(
'FlagExpectations', 'foo')
filesystem.write_text_file(
flag_expectations_file,
'# results: [ Failure ]\nsomething/pass-unexpectedly-mac.html [ Failure ]'
)
self._setup_mock_results(host.results_fetcher)
cmd = ['update', '--flag=--foo']
TryFlag(cmd, host, MockGitCL(host, self.mock_try_results)).run()
self.assertEqual(
host.stdout.getvalue(), '\n'.join([
'Fetching results...', '', '### 1 unexpected passes:', '',
'[ Mac ] something/pass-unexpectedly-mac.html [ Pass ]', '',
'### 5 unexpected failures:', '',
'[ Linux ] something/fail-everywhere.html [ Failure ]',
'[ Mac ] something/fail-everywhere.html [ Failure ]',
'[ Win ] something/fail-everywhere.html [ Failure ]',
'[ Linux ] something/fail-win-and-linux.html [ Failure ]',
'[ Win ] something/fail-win-and-linux.html [ Failure ]', ''
]))
def test_update_irrelevant_unexpected_pass(self):
host = MockHost()
filesystem = host.filesystem
finder = PathFinder(filesystem)
flag_expectations_file = finder.path_from_web_tests(
'FlagExpectations', 'foo')
self._setup_mock_results(host.results_fetcher)
cmd = ['update', '--flag=--foo']
# Unexpected passes that don't have flag-specific failure expectations
# should not be reported.
filesystem.write_text_file(flag_expectations_file, '')
TryFlag(cmd, host, MockGitCL(host, self.mock_try_results)).run()
self.assertTrue('### 0 unexpected passes' in host.stdout.getvalue())
def test_invalid_action(self):
host = MockHost()
cmd = ['invalid', '--flag=--foo']
TryFlag(cmd, host, MockGitCL(host)).run()
self.assertEqual(host.stderr.getvalue(),
'specify "trigger" or "update"\n')