Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_expectations_updater_unittest.py

Issue 2680393003: Preliminary refactoring to improve test expectation specifiers added by importer. (Closed)
Patch Set: Rebased Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_expectations_updater.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import copy 6 import copy
7 7
8 from webkitpy.common.host_mock import MockHost 8 from webkitpy.common.host_mock import MockHost
9 from webkitpy.common.net.buildbot import Build 9 from webkitpy.common.net.buildbot import Build
10 from webkitpy.common.net.buildbot_mock import MockBuildBot 10 from webkitpy.common.net.buildbot_mock import MockBuildBot
11 from webkitpy.common.net.layout_test_results import LayoutTestResult, LayoutTest Results 11 from webkitpy.common.net.layout_test_results import LayoutTestResult, LayoutTest Results
12 from webkitpy.common.net.web_mock import MockWeb 12 from webkitpy.common.net.web_mock import MockWeb
13 from webkitpy.common.system.log_testing import LoggingTestCase 13 from webkitpy.common.system.log_testing import LoggingTestCase
14 from webkitpy.layout_tests.builder_list import BuilderList 14 from webkitpy.layout_tests.builder_list import BuilderList
15 from webkitpy.w3c.wpt_expectations_updater import WPTExpectationsUpdater, MARKER _COMMENT 15 from webkitpy.w3c.wpt_expectations_updater import WPTExpectationsUpdater, MARKER _COMMENT
16 16
17 17
18 class WPTExpectationsUpdaterTest(LoggingTestCase): 18 class WPTExpectationsUpdaterTest(LoggingTestCase):
19 19
20 def setUp(self): 20 def mock_host(self):
21 super(WPTExpectationsUpdaterTest, self).setUp() 21 super(WPTExpectationsUpdaterTest, self).setUp()
22 self.host = MockHost() 22 host = MockHost()
23 self.host.builders = BuilderList({ 23 host.builders = BuilderList({
24 'mac': {'port_name': 'test-mac'}, 24 'MOCK Mac10.10': {'port_name': 'test-mac-mac10.10', 'specifiers': [' Mac10.10', 'Release']},
25 'MOCK Mac10.11': {'port_name': 'test-mac-mac10.11', 'specifiers': [' Mac10.11', 'Release']},
26 'MOCK Trusty': {'port_name': 'test-linux-trusty', 'specifiers': ['Tr usty', 'Release']},
27 'MOCK Win10': {'port_name': 'test-win-win10', 'specifiers': ['Win10' , 'Release']},
28 'MOCK Win7': {'port_name': 'test-win-win7', 'specifiers': ['Win7', ' Release']},
29 'MOCK Android': {'port_name': 'test-android', 'specifiers': ['Androi d', 'Release']},
25 }) 30 })
31 return host
26 32
27 def test_get_failing_results_dict_only_passing_results(self): 33 def test_get_failing_results_dict_only_passing_results(self):
28 self.host.buildbot.set_results(Build('mac', 123), LayoutTestResults({ 34 host = self.mock_host()
35 host.buildbot.set_results(Build('MOCK Mac10.10', 123), LayoutTestResults ({
29 'tests': { 36 'tests': {
30 'x': { 37 'x': {
31 'passing-test.html': { 38 'passing-test.html': {
32 'expected': 'PASS', 39 'expected': 'PASS',
33 'actual': 'PASS', 40 'actual': 'PASS',
34 }, 41 },
35 }, 42 },
36 }, 43 },
37 })) 44 }))
38 updater = WPTExpectationsUpdater(self.host) 45 updater = WPTExpectationsUpdater(host)
39 self.assertEqual(updater.get_failing_results_dict(Build('mac', 123)), {} ) 46 self.assertEqual(updater.get_failing_results_dict(Build('MOCK Mac10.10', 123)), {})
40 47
41 def test_get_failing_results_dict_no_results(self): 48 def test_get_failing_results_dict_no_results(self):
42 self.host.buildbot = MockBuildBot() 49 host = self.mock_host()
43 self.host.buildbot.set_results(Build('mac', 123), None) 50 host.buildbot = MockBuildBot()
44 updater = WPTExpectationsUpdater(self.host) 51 host.buildbot.set_results(Build('MOCK Mac10.10', 123), None)
45 self.assertEqual(updater.get_failing_results_dict(Build('mac', 123)), {} ) 52 updater = WPTExpectationsUpdater(host)
53 self.assertEqual(updater.get_failing_results_dict(Build('MOCK Mac10.10', 123)), {})
46 54
47 def test_get_failing_results_dict_some_failing_results(self): 55 def test_get_failing_results_dict_some_failing_results(self):
48 self.host.buildbot.set_results(Build('mac', 123), LayoutTestResults({ 56 host = self.mock_host()
57 host.buildbot.set_results(Build('MOCK Mac10.10', 123), LayoutTestResults ({
49 'tests': { 58 'tests': {
50 'x': { 59 'x': {
51 'failing-test.html': { 60 'failing-test.html': {
52 'expected': 'PASS', 61 'expected': 'PASS',
53 'actual': 'IMAGE', 62 'actual': 'IMAGE',
54 'is_unexpected': True, 63 'is_unexpected': True,
55 }, 64 },
56 }, 65 },
57 }, 66 },
58 })) 67 }))
59 updater = WPTExpectationsUpdater(self.host) 68 updater = WPTExpectationsUpdater(host)
60 self.assertEqual(updater.get_failing_results_dict(Build('mac', 123)), { 69 results_dict = updater.get_failing_results_dict(Build('MOCK Mac10.10', 1 23))
61 'x/failing-test.html': { 70 self.assertEqual(
62 'Mac': { 71 results_dict,
63 'actual': 'IMAGE', 72 {
64 'expected': 'PASS', 73 'x/failing-test.html': {
65 'bug': 'crbug.com/626703', 74 'test-mac-mac10.10': {
75 'actual': 'IMAGE',
76 'expected': 'PASS',
77 'bug': 'crbug.com/626703',
78 },
66 }, 79 },
67 }, 80 })
68 })
69 81
70 def test_merge_same_valued_keys_all_match(self): 82 def test_merge_same_valued_keys_all_match(self):
71 updater = WPTExpectationsUpdater(self.host) 83 updater = WPTExpectationsUpdater(self.mock_host())
72 self.assertEqual( 84 self.assertEqual(
73 updater.merge_same_valued_keys({ 85 updater.merge_same_valued_keys({
74 'one': {'expected': 'FAIL', 'actual': 'PASS'}, 86 'one': {'expected': 'FAIL', 'actual': 'PASS'},
75 'two': {'expected': 'FAIL', 'actual': 'PASS'}, 87 'two': {'expected': 'FAIL', 'actual': 'PASS'},
76 }), 88 }),
77 {('two', 'one'): {'expected': 'FAIL', 'actual': 'PASS'}}) 89 {('two', 'one'): {'expected': 'FAIL', 'actual': 'PASS'}})
78 90
79 def test_merge_same_valued_keys_one_mismatch(self): 91 def test_merge_same_valued_keys_one_mismatch(self):
80 updater = WPTExpectationsUpdater(self.host) 92 updater = WPTExpectationsUpdater(self.mock_host())
81 self.assertEqual( 93 self.assertEqual(
82 updater.merge_same_valued_keys({ 94 updater.merge_same_valued_keys({
83 'one': {'expected': 'FAIL', 'actual': 'PASS'}, 95 'one': {'expected': 'FAIL', 'actual': 'PASS'},
84 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'}, 96 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'},
85 'three': {'expected': 'FAIL', 'actual': 'PASS'}, 97 'three': {'expected': 'FAIL', 'actual': 'PASS'},
86 }), 98 }),
87 { 99 {
88 ('three', 'one'): {'expected': 'FAIL', 'actual': 'PASS'}, 100 ('three', 'one'): {'expected': 'FAIL', 'actual': 'PASS'},
89 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'}, 101 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'},
90 }) 102 })
91 103
92 def test_get_expectations(self): 104 def test_get_expectations(self):
93 updater = WPTExpectationsUpdater(self.host) 105 updater = WPTExpectationsUpdater(self.mock_host())
94 self.assertEqual( 106 self.assertEqual(
95 updater.get_expectations({'expected': 'FAIL', 'actual': 'PASS'}), 107 updater.get_expectations({'expected': 'FAIL', 'actual': 'PASS'}),
96 {'Pass'}) 108 {'Pass'})
97 self.assertEqual( 109 self.assertEqual(
98 updater.get_expectations({'expected': 'FAIL', 'actual': 'TIMEOUT'}), 110 updater.get_expectations({'expected': 'FAIL', 'actual': 'TIMEOUT'}),
99 {'Timeout'}) 111 {'Timeout'})
100 self.assertEqual( 112 self.assertEqual(
101 updater.get_expectations({'expected': 'TIMEOUT', 'actual': 'PASS'}), 113 updater.get_expectations({'expected': 'TIMEOUT', 'actual': 'PASS'}),
102 {'Pass'}) 114 {'Pass'})
103 self.assertEqual( 115 self.assertEqual(
104 updater.get_expectations({'expected': 'PASS', 'actual': 'TIMEOUT CRA SH FAIL'}), 116 updater.get_expectations({'expected': 'PASS', 'actual': 'TIMEOUT CRA SH FAIL'}),
105 {'Crash', 'Failure', 'Timeout'}) 117 {'Crash', 'Failure', 'Timeout'})
106 self.assertEqual( 118 self.assertEqual(
107 updater.get_expectations({'expected': 'SLOW CRASH FAIL TIMEOUT', 'ac tual': 'PASS'}), 119 updater.get_expectations({'expected': 'SLOW CRASH FAIL TIMEOUT', 'ac tual': 'PASS'}),
108 {'Pass'}) 120 {'Pass'})
109 121
110 def test_create_line_list_old_tests(self): 122 def test_create_line_list_old_tests(self):
111 # In this example, there are two failures that are not in w3c tests. 123 # In this example, there are two failures that are not in w3c tests.
112 updater = WPTExpectationsUpdater(self.host) 124 updater = WPTExpectationsUpdater(self.mock_host())
113 results = { 125 results = {
114 'fake/test/path.html': { 126 'fake/test/path.html': {
115 'one': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'}, 127 'one': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'},
116 'two': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'}, 128 'two': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'},
117 } 129 }
118 } 130 }
119 self.assertEqual(updater.create_line_list(results), []) 131 self.assertEqual(updater.create_line_list(results), [])
120 132
121 def test_create_line_list_new_tests(self): 133 def test_create_line_list_new_tests(self):
122 # In this example, there are unexpected non-fail results in w3c tests. 134 # In this example, there are unexpected non-fail results in w3c tests.
123 updater = WPTExpectationsUpdater(self.host) 135 updater = WPTExpectationsUpdater(self.mock_host())
124 results = { 136 results = {
125 'external/fake/test/path.html': { 137 'external/fake/test/path.html': {
126 'one': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'}, 138 'one': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'},
127 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT', 'bug': 'crbug.c om/test'}, 139 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT', 'bug': 'crbug.c om/test'},
128 'three': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.co m/test'}, 140 'three': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.co m/test'},
129 } 141 }
130 } 142 }
131 self.assertEqual( 143 self.assertEqual(
132 updater.create_line_list(results), 144 updater.create_line_list(results),
133 [ 145 [
134 'crbug.com/test [ three ] external/fake/test/path.html [ Pass ]' , 146 'crbug.com/test [ three ] external/fake/test/path.html [ Pass ]' ,
135 'crbug.com/test [ two ] external/fake/test/path.html [ Timeout ] ', 147 'crbug.com/test [ two ] external/fake/test/path.html [ Timeout ] ',
136 'crbug.com/test [ one ] external/fake/test/path.html [ Pass ]', 148 'crbug.com/test [ one ] external/fake/test/path.html [ Pass ]',
137 ]) 149 ])
138 150
139 def test_merge_dicts_with_conflict_raise_exception(self): 151 def test_merge_dicts_with_conflict_raise_exception(self):
140 updater = WPTExpectationsUpdater(self.host) 152 updater = WPTExpectationsUpdater(self.mock_host())
141 # Both dicts here have the key "one", and the value is not equal. 153 # Both dicts here have the key "one", and the value is not equal.
142 with self.assertRaises(ValueError): 154 with self.assertRaises(ValueError):
143 updater.merge_dicts( 155 updater.merge_dicts(
144 { 156 {
145 'external/fake/test/path.html': { 157 'external/fake/test/path.html': {
146 'one': {'expected': 'FAIL', 'actual': 'PASS'}, 158 'one': {'expected': 'FAIL', 'actual': 'PASS'},
147 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'}, 159 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'},
148 'three': {'expected': 'FAIL', 'actual': 'PASS'}, 160 'three': {'expected': 'FAIL', 'actual': 'PASS'},
149 }, 161 },
150 }, 162 },
151 { 163 {
152 'external/fake/test/path.html': { 164 'external/fake/test/path.html': {
153 'one': {'expected': 'FAIL', 'actual': 'TIMEOUT'}, 165 'one': {'expected': 'FAIL', 'actual': 'TIMEOUT'},
154 } 166 }
155 }) 167 })
156 168
157 def test_merge_dicts_merges_second_dict_into_first(self): 169 def test_merge_dicts_merges_second_dict_into_first(self):
158 updater = WPTExpectationsUpdater(self.host) 170 updater = WPTExpectationsUpdater(self.mock_host())
159 one = { 171 one = {
160 'fake/test/path.html': { 172 'fake/test/path.html': {
161 'one': {'expected': 'FAIL', 'actual': 'PASS'}, 173 'one': {'expected': 'FAIL', 'actual': 'PASS'},
162 'two': {'expected': 'FAIL', 'actual': 'PASS'}, 174 'two': {'expected': 'FAIL', 'actual': 'PASS'},
163 } 175 }
164 } 176 }
165 two = { 177 two = {
166 'external/fake/test/path.html': { 178 'external/fake/test/path.html': {
167 'one': {'expected': 'FAIL', 'actual': 'PASS'}, 179 'one': {'expected': 'FAIL', 'actual': 'PASS'},
168 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'}, 180 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'},
169 'three': {'expected': 'FAIL', 'actual': 'PASS'}, 181 'three': {'expected': 'FAIL', 'actual': 'PASS'},
170 } 182 }
171 } 183 }
172 three = { 184 three = {
173 'external/fake/test/path.html': { 185 'external/fake/test/path.html': {
174 'four': {'expected': 'FAIL', 'actual': 'PASS'}, 186 'four': {'expected': 'FAIL', 'actual': 'PASS'},
175 } 187 }
176 } 188 }
177 189
178 output = updater.merge_dicts(one, three) 190 output = updater.merge_dicts(one, three)
179 self.assertEqual(output, one) 191 self.assertEqual(output, one)
180 output = updater.merge_dicts(two, three) 192 output = updater.merge_dicts(two, three)
181 self.assertEqual(output, two) 193 self.assertEqual(output, two)
182 194
183 def test_generate_results_dict(self): 195 def test_generate_results_dict(self):
184 updater = WPTExpectationsUpdater(MockHost()) 196 updater = WPTExpectationsUpdater(self.mock_host())
185 layout_test_list = [ 197 layout_test_list = [
186 LayoutTestResult( 198 LayoutTestResult(
187 'test/name.html', { 199 'test/name.html', {
188 'expected': 'bar', 200 'expected': 'bar',
189 'actual': 'foo', 201 'actual': 'foo',
190 'is_unexpected': True, 202 'is_unexpected': True,
191 'has_stderr': True, 203 'has_stderr': True,
192 } 204 })
193 )] 205 ]
194 self.assertEqual(updater.generate_results_dict('dummy_platform', layout_ test_list), { 206 self.assertEqual(updater.generate_results_dict('test-mac-mac10.10', layo ut_test_list), {
195 'test/name.html': { 207 'test/name.html': {
196 'dummy_platform': { 208 'test-mac-mac10.10': {
197 'expected': 'bar', 209 'expected': 'bar',
198 'actual': 'foo', 210 'actual': 'foo',
199 'bug': 'crbug.com/626703', 211 'bug': 'crbug.com/626703',
200 } 212 }
201 } 213 }
202 }) 214 })
203 215
204 def test_write_to_test_expectations_with_marker_comment(self): 216 def test_write_to_test_expectations_with_marker_comment(self):
217 host = self.mock_host()
205 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations' 218 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations'
206 self.host.filesystem.files[expectations_path] = MARKER_COMMENT + '\n' 219 host.filesystem.files[expectations_path] = MARKER_COMMENT + '\n'
207 updater = WPTExpectationsUpdater(self.host) 220 updater = WPTExpectationsUpdater(host)
208 line_list = ['crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]'] 221 line_list = ['crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]']
209 updater.write_to_test_expectations(line_list) 222 updater.write_to_test_expectations(line_list)
210 value = updater.host.filesystem.read_text_file(expectations_path) 223 value = updater.host.filesystem.read_text_file(expectations_path)
211 self.assertMultiLineEqual( 224 self.assertMultiLineEqual(
212 value, 225 value,
213 (MARKER_COMMENT + '\n' 226 (MARKER_COMMENT + '\n'
214 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]\n')) 227 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]\n'))
215 228
216 def test_write_to_test_expectations_with_no_marker_comment(self): 229 def test_write_to_test_expectations_with_no_marker_comment(self):
230 host = self.mock_host()
217 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations' 231 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations'
218 self.host.filesystem.files[expectations_path] = 'crbug.com/111 [ FakePla tform ]\n' 232 host.filesystem.files[expectations_path] = 'crbug.com/111 [ FakePlatform ]\n'
219 updater = WPTExpectationsUpdater(self.host) 233 updater = WPTExpectationsUpdater(host)
220 line_list = ['crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]'] 234 line_list = ['crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]']
221 updater.write_to_test_expectations(line_list) 235 updater.write_to_test_expectations(line_list)
222 value = self.host.filesystem.read_text_file(expectations_path) 236 value = host.filesystem.read_text_file(expectations_path)
223 self.assertMultiLineEqual( 237 self.assertMultiLineEqual(
224 value, 238 value,
225 ('crbug.com/111 [ FakePlatform ]\n' 239 ('crbug.com/111 [ FakePlatform ]\n'
226 '\n' + MARKER_COMMENT + '\n' 240 '\n' + MARKER_COMMENT + '\n'
227 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]')) 241 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]'))
228 242
229 def test_write_to_test_expectations_skips_existing_lines(self): 243 def test_write_to_test_expectations_skips_existing_lines(self):
244 host = self.mock_host()
230 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations' 245 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations'
231 self.host.filesystem.files[expectations_path] = 'crbug.com/111 dont/copy /me.html [ Failure ]\n' 246 host.filesystem.files[expectations_path] = 'crbug.com/111 dont/copy/me.h tml [ Failure ]\n'
232 updater = WPTExpectationsUpdater(self.host) 247 updater = WPTExpectationsUpdater(host)
233 line_list = [ 248 line_list = [
234 'crbug.com/111 dont/copy/me.html [ Failure ]', 249 'crbug.com/111 dont/copy/me.html [ Failure ]',
235 'crbug.com/222 do/copy/me.html [ Failure ]' 250 'crbug.com/222 do/copy/me.html [ Failure ]'
236 ] 251 ]
237 updater.write_to_test_expectations(line_list) 252 updater.write_to_test_expectations(line_list)
238 value = self.host.filesystem.read_text_file(expectations_path) 253 value = host.filesystem.read_text_file(expectations_path)
239 self.assertEqual( 254 self.assertEqual(
240 value, 255 value,
241 ('crbug.com/111 dont/copy/me.html [ Failure ]\n' 256 ('crbug.com/111 dont/copy/me.html [ Failure ]\n'
242 '\n' + MARKER_COMMENT + '\n' 257 '\n' + MARKER_COMMENT + '\n'
243 'crbug.com/222 do/copy/me.html [ Failure ]')) 258 'crbug.com/222 do/copy/me.html [ Failure ]'))
244 259
245 def test_write_to_test_expectations_with_marker_and_no_lines(self): 260 def test_write_to_test_expectations_with_marker_and_no_lines(self):
261 host = self.mock_host()
246 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations' 262 expectations_path = '/mock-checkout/third_party/WebKit/LayoutTests/TestE xpectations'
247 self.host.filesystem.files[expectations_path] = ( 263 host.filesystem.files[expectations_path] = (
248 MARKER_COMMENT + '\n' 264 MARKER_COMMENT + '\n'
249 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]\n') 265 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]\n')
250 updater = WPTExpectationsUpdater(self.host) 266 updater = WPTExpectationsUpdater(host)
251 updater.write_to_test_expectations([]) 267 updater.write_to_test_expectations([])
252 value = updater.host.filesystem.read_text_file(expectations_path) 268 value = updater.host.filesystem.read_text_file(expectations_path)
253 self.assertMultiLineEqual( 269 self.assertMultiLineEqual(
254 value, 270 value,
255 (MARKER_COMMENT + '\n' 271 (MARKER_COMMENT + '\n'
256 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]\n')) 272 'crbug.com/123 [ FakePlatform ] fake/file/path.html [ Pass ]\n'))
257 273
258 def test_is_js_test_true(self): 274 def test_is_js_test_true(self):
259 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/foo/bar.html'] = ( 275 host = self.mock_host()
276 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/foo /bar.html'] = (
260 '<script src="/resources/testharness.js"></script>') 277 '<script src="/resources/testharness.js"></script>')
261 updater = WPTExpectationsUpdater(self.host) 278 updater = WPTExpectationsUpdater(host)
262 self.assertTrue(updater.is_js_test('foo/bar.html')) 279 self.assertTrue(updater.is_js_test('foo/bar.html'))
263 280
264 def test_is_js_test_false(self): 281 def test_is_js_test_false(self):
265 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/foo/bar.html'] = ( 282 host = self.mock_host()
283 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/foo /bar.html'] = (
266 '<script src="ref-test.html"></script>') 284 '<script src="ref-test.html"></script>')
267 updater = WPTExpectationsUpdater(self.host) 285 updater = WPTExpectationsUpdater(host)
268 self.assertFalse(updater.is_js_test('foo/bar.html')) 286 self.assertFalse(updater.is_js_test('foo/bar.html'))
269 287
270 def test_is_js_test_non_existent_file(self): 288 def test_is_js_test_non_existent_file(self):
271 updater = WPTExpectationsUpdater(self.host) 289 updater = WPTExpectationsUpdater(self.mock_host())
272 self.assertFalse(updater.is_js_test('foo/bar.html')) 290 self.assertFalse(updater.is_js_test('foo/bar.html'))
273 291
274 def test_get_test_to_rebaseline_returns_only_tests_with_failures(self): 292 def test_get_test_to_rebaseline_returns_only_tests_with_failures(self):
275 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/external/fake/test/path.html'] = ( 293 host = self.mock_host()
294 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/ext ernal/fake/test/path.html'] = (
276 '<script src="/resources/testharness.js"></script>') 295 '<script src="/resources/testharness.js"></script>')
277 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/external/other/test/path.html'] = ( 296 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/ext ernal/other/test/path.html'] = (
278 '<script src="/resources/testharness.js"></script>') 297 '<script src="/resources/testharness.js"></script>')
279 updater = WPTExpectationsUpdater(self.host) 298 updater = WPTExpectationsUpdater(host)
280 two = { 299 two = {
281 'external/fake/test/path.html': { 300 'external/fake/test/path.html': {
282 'one': {'expected': 'FAIL', 'actual': 'PASS'}, 301 'one': {'expected': 'FAIL', 'actual': 'PASS'},
283 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'}, 302 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT'},
284 'three': {'expected': 'FAIL', 'actual': 'PASS'}, 303 'three': {'expected': 'FAIL', 'actual': 'PASS'},
285 } 304 }
286 } 305 }
287 tests_to_rebaseline, _ = updater.get_tests_to_rebaseline(two) 306 tests_to_rebaseline, _ = updater.get_tests_to_rebaseline(two)
288 # The other test doesn't have an entry in the test results dict, so it i s not listed as a test to rebaseline. 307 # The other test doesn't have an entry in the test results dict, so it i s not listed as a test to rebaseline.
289 self.assertEqual(tests_to_rebaseline, ['external/fake/test/path.html']) 308 self.assertEqual(tests_to_rebaseline, ['external/fake/test/path.html'])
290 309
291 def test_get_test_to_rebaseline_returns_only_js_tests(self): 310 def test_get_test_to_rebaseline_returns_only_js_tests(self):
292 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/external/fake/test/path.html'] = ( 311 host = self.mock_host()
312 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/ext ernal/fake/test/path.html'] = (
293 'this file does not look like a testharness JS test.') 313 'this file does not look like a testharness JS test.')
294 updater = WPTExpectationsUpdater(self.host) 314 updater = WPTExpectationsUpdater(host)
295 two = { 315 two = {
296 'external/fake/test/path.html': { 316 'external/fake/test/path.html': {
297 'one': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'}, 317 'one': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.com/ test'},
298 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT', 'bug': 'crbug.c om/test'}, 318 'two': {'expected': 'FAIL', 'actual': 'TIMEOUT', 'bug': 'crbug.c om/test'},
299 'three': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.co m/test'}, 319 'three': {'expected': 'FAIL', 'actual': 'PASS', 'bug': 'crbug.co m/test'},
300 } 320 }
301 } 321 }
302 tests_to_rebaseline, _ = updater.get_tests_to_rebaseline(two) 322 tests_to_rebaseline, _ = updater.get_tests_to_rebaseline(two)
303 self.assertEqual(tests_to_rebaseline, []) 323 self.assertEqual(tests_to_rebaseline, [])
304 324
305 def test_get_tests_to_rebaseline_returns_updated_dict(self): 325 def test_get_tests_to_rebaseline_returns_updated_dict(self):
326 host = self.mock_host()
306 test_results_dict = { 327 test_results_dict = {
307 'external/fake/test/path.html': { 328 'external/fake/test/path.html': {
308 'one': {'expected': 'PASS', 'actual': 'TEXT'}, 329 'one': {'expected': 'PASS', 'actual': 'TEXT'},
309 'two': {'expected': 'PASS', 'actual': 'TIMEOUT'}, 330 'two': {'expected': 'PASS', 'actual': 'TIMEOUT'},
310 }, 331 },
311 } 332 }
312 test_results_dict_copy = copy.deepcopy(test_results_dict) 333 test_results_dict_copy = copy.deepcopy(test_results_dict)
313 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/external/fake/test/path.html'] = ( 334 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/ext ernal/fake/test/path.html'] = (
314 '<script src="/resources/testharness.js"></script>') 335 '<script src="/resources/testharness.js"></script>')
315 updater = WPTExpectationsUpdater(self.host) 336 updater = WPTExpectationsUpdater(host)
316 tests_to_rebaseline, modified_test_results = updater.get_tests_to_rebase line( 337 tests_to_rebaseline, modified_test_results = updater.get_tests_to_rebase line(
317 test_results_dict) 338 test_results_dict)
318 self.assertEqual(tests_to_rebaseline, ['external/fake/test/path.html']) 339 self.assertEqual(tests_to_rebaseline, ['external/fake/test/path.html'])
319 # The record for the builder with a timeout is kept, but not with a text mismatch, 340 # The record for the builder with a timeout is kept, but not with a text mismatch,
320 # since that should be covered by downloading a new baseline. 341 # since that should be covered by downloading a new baseline.
321 self.assertEqual(modified_test_results, { 342 self.assertEqual(modified_test_results, {
322 'external/fake/test/path.html': { 343 'external/fake/test/path.html': {
323 'two': {'expected': 'PASS', 'actual': 'TIMEOUT'}, 344 'two': {'expected': 'PASS', 'actual': 'TIMEOUT'},
324 }, 345 },
325 }) 346 })
326 # The original dict isn't modified. 347 # The original dict isn't modified.
327 self.assertEqual(test_results_dict, test_results_dict_copy) 348 self.assertEqual(test_results_dict, test_results_dict_copy)
328 349
329 def test_get_tests_to_rebaseline_also_returns_slow_tests(self): 350 def test_get_tests_to_rebaseline_also_returns_slow_tests(self):
351 host = self.mock_host()
330 test_results_dict = { 352 test_results_dict = {
331 'external/fake/test/path.html': { 353 'external/fake/test/path.html': {
332 'one': {'expected': 'SLOW', 'actual': 'TEXT'}, 354 'one': {'expected': 'SLOW', 'actual': 'TEXT'},
333 'two': {'expected': 'SLOW', 'actual': 'TIMEOUT'}, 355 'two': {'expected': 'SLOW', 'actual': 'TIMEOUT'},
334 }, 356 },
335 } 357 }
336 test_results_dict_copy = copy.deepcopy(test_results_dict) 358 test_results_dict_copy = copy.deepcopy(test_results_dict)
337 self.host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTest s/external/fake/test/path.html'] = ( 359 host.filesystem.files['/mock-checkout/third_party/WebKit/LayoutTests/ext ernal/fake/test/path.html'] = (
338 '<script src="/resources/testharness.js"></script>') 360 '<script src="/resources/testharness.js"></script>')
339 updater = WPTExpectationsUpdater(self.host) 361 updater = WPTExpectationsUpdater(host)
340 tests_to_rebaseline, modified_test_results = updater.get_tests_to_rebase line( 362 tests_to_rebaseline, modified_test_results = updater.get_tests_to_rebase line(
341 test_results_dict) 363 test_results_dict)
342 self.assertEqual(tests_to_rebaseline, ['external/fake/test/path.html']) 364 self.assertEqual(tests_to_rebaseline, ['external/fake/test/path.html'])
343 # The record for the builder with a timeout is kept, but not with a text mismatch, 365 # The record for the builder with a timeout is kept, but not with a text mismatch,
344 # since that should be covered by downloading a new baseline. 366 # since that should be covered by downloading a new baseline.
345 self.assertEqual(modified_test_results, { 367 self.assertEqual(modified_test_results, {
346 'external/fake/test/path.html': { 368 'external/fake/test/path.html': {
347 'two': {'expected': 'SLOW', 'actual': 'TIMEOUT'}, 369 'two': {'expected': 'SLOW', 'actual': 'TIMEOUT'},
348 }, 370 },
349 }) 371 })
350 # The original dict isn't modified. 372 # The original dict isn't modified.
351 self.assertEqual(test_results_dict, test_results_dict_copy) 373 self.assertEqual(test_results_dict, test_results_dict_copy)
352 374
353 def test_run_no_issue_number(self): 375 def test_run_no_issue_number(self):
354 updater = WPTExpectationsUpdater(self.host) 376 updater = WPTExpectationsUpdater(self.mock_host())
355 updater.get_issue_number = lambda: 'None' 377 updater.get_issue_number = lambda: 'None'
356 self.assertEqual(1, updater.run(args=[])) 378 self.assertEqual(1, updater.run(args=[]))
357 self.assertLog(['ERROR: No issue on current branch.\n']) 379 self.assertLog(['ERROR: No issue on current branch.\n'])
358 380
359 def test_run_no_try_results(self): 381 def test_run_no_try_results(self):
360 self.host.web = MockWeb(urls={ 382 host = self.mock_host()
383 host.web = MockWeb(urls={
361 'https://codereview.chromium.org/api/11112222': json.dumps({ 384 'https://codereview.chromium.org/api/11112222': json.dumps({
362 'patchsets': [1], 385 'patchsets': [1],
363 }), 386 }),
364 'https://codereview.chromium.org/api/11112222/1': json.dumps({ 387 'https://codereview.chromium.org/api/11112222/1': json.dumps({
365 'try_job_results': [] 388 'try_job_results': []
366 }) 389 })
367 }) 390 })
368 updater = WPTExpectationsUpdater(self.host) 391 updater = WPTExpectationsUpdater(host)
369 updater.get_issue_number = lambda: '11112222' 392 updater.get_issue_number = lambda: '11112222'
370 updater.get_try_bots = lambda: ['test-builder-name'] 393 updater.get_try_bots = lambda: ['test-builder-name']
371 self.assertEqual(1, updater.run(args=[])) 394 self.assertEqual(1, updater.run(args=[]))
372 self.assertEqual( 395 self.assertEqual(
373 self.host.web.urls_fetched, 396 host.web.urls_fetched,
374 [ 397 [
375 'https://codereview.chromium.org/api/11112222', 398 'https://codereview.chromium.org/api/11112222',
376 'https://codereview.chromium.org/api/11112222/1' 399 'https://codereview.chromium.org/api/11112222/1'
377 ]) 400 ])
378 self.assertLog(['ERROR: No try job information was collected.\n']) 401 self.assertLog(['ERROR: No try job information was collected.\n'])
OLDNEW
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_expectations_updater.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698