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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py

Issue 2329263002: Run format-webkitpy and fix long lines. (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return MockSCM.delete_list(self, paths) 55 return MockSCM.delete_list(self, paths)
56 56
57 def move(self, origin, destination): 57 def move(self, origin, destination):
58 if origin in self._exclusion_list: 58 if origin in self._exclusion_list:
59 raise Exception("File is not SCM managed: " + origin) 59 raise Exception("File is not SCM managed: " + origin)
60 return MockSCM.move(self, origin, destination) 60 return MockSCM.move(self, origin, destination)
61 61
62 62
63 class BaselineOptimizerTest(unittest.TestCase): 63 class BaselineOptimizerTest(unittest.TestCase):
64 64
65 # Protected method _move_baselines is tested below - pylint: disable=protect ed-access
65 def test_move_baselines(self): 66 def test_move_baselines(self):
66 host = MockHost(scm=ExcludingMockSCM( 67 host = MockHost(scm=ExcludingMockSCM(
67 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another /test-expected.txt'])) 68 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another /test-expected.txt']))
68 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]') 69 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]')
69 host.filesystem.write_binary_file( 70 host.filesystem.write_binary_file(
70 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A') 71 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A')
71 host.filesystem.write_binary_file( 72 host.filesystem.write_binary_file(
72 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A') 73 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A')
73 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B') 74 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B')
74 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( 75 baseline_optimizer = BaselineOptimizer(
75 ), host.port_factory.all_port_names(), skip_scm_commands=False) 76 host, host.port_factory.get(), host.port_factory.all_port_names(), s kip_scm_commands=False)
76 baseline_optimizer._move_baselines('another/test-expected.txt', { 77 baseline_optimizer._move_baselines(
77 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', 78 'another/test-expected.txt',
78 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', 79 {
79 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', 80 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a aa',
80 }, { 81 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a aa',
81 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', 82 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb',
82 }) 83 },
84 {
85 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa',
86 })
83 self.assertEqual(host.filesystem.read_binary_file( 87 self.assertEqual(host.filesystem.read_binary_file(
84 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt'), 'result A') 88 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt'), 'result A')
85 89
86 def test_move_baselines_skip_scm_commands(self): 90 def test_move_baselines_skip_scm_commands(self):
87 host = MockHost(scm=ExcludingMockSCM( 91 host = MockHost(scm=ExcludingMockSCM(
88 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another /test-expected.txt'])) 92 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another /test-expected.txt']))
89 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]') 93 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]')
90 host.filesystem.write_binary_file( 94 host.filesystem.write_binary_file(
91 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A') 95 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A')
92 host.filesystem.write_binary_file( 96 host.filesystem.write_binary_file(
93 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A') 97 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A')
94 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B') 98 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B')
95 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( 99 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(
96 ), host.port_factory.all_port_names(), skip_scm_commands=True) 100 ), host.port_factory.all_port_names(), skip_scm_commands=True)
97 baseline_optimizer._move_baselines('another/test-expected.txt', { 101 baseline_optimizer._move_baselines(
98 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', 102 'another/test-expected.txt',
99 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', 103 {
100 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', 104 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a aa',
101 }, { 105 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a aa',
102 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb ', 106 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb',
103 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', 107 },
104 }) 108 {
105 self.assertEqual(host.filesystem.read_binary_file( 109 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb',
106 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt'), 'result A') 110 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa',
111 })
112 self.assertEqual(
113 host.filesystem.read_binary_file(
114 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe cted.txt'),
115 'result A')
107 116
108 self.assertEqual(baseline_optimizer._files_to_delete, [ 117 self.assertEqual(
109 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 118 baseline_optimizer._files_to_delete,
110 ]) 119 [
120 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/anot her/test-expected.txt',
121 ])
111 122
112 self.assertEqual(baseline_optimizer._files_to_add, [ 123 self.assertEqual(
113 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt', 124 baseline_optimizer._files_to_add,
114 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/anothe r/test-expected.txt', 125 [
115 ]) 126 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe cted.txt',
127 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/an other/test-expected.txt',
128 ])
116 129
117 def _assertOptimization(self, results_by_directory, expected_new_results_by_ directory, 130 def _assertOptimization(self, results_by_directory, expected_new_results_by_ directory,
118 baseline_dirname='', expected_files_to_delete=None, host=None): 131 baseline_dirname='', expected_files_to_delete=None, host=None):
119 if not host: 132 if not host:
120 host = MockHost() 133 host = MockHost()
121 fs = host.filesystem 134 fs = host.filesystem
122 webkit_base = WebKitFinder(fs).webkit_base() 135 webkit_base = WebKitFinder(fs).webkit_base()
123 baseline_name = 'mock-baseline-expected.txt' 136 baseline_name = 'mock-baseline-expected.txt'
124 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'), 137 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'),
125 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]') 138 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]')
(...skipping 16 matching lines...) Expand all
142 # Check that the files that were in the original set have been deleted w here necessary. 155 # Check that the files that were in the original set have been deleted w here necessary.
143 for dirname in results_by_directory: 156 for dirname in results_by_directory:
144 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) 157 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name)
145 if not dirname in expected_new_results_by_directory: 158 if not dirname in expected_new_results_by_directory:
146 self.assertTrue(not fs.exists(path) or path in baseline_optimize r._files_to_delete) 159 self.assertTrue(not fs.exists(path) or path in baseline_optimize r._files_to_delete)
147 160
148 if expected_files_to_delete: 161 if expected_files_to_delete:
149 self.assertEqual(sorted(baseline_optimizer._files_to_delete), sorted (expected_files_to_delete)) 162 self.assertEqual(sorted(baseline_optimizer._files_to_delete), sorted (expected_files_to_delete))
150 163
151 def test_linux_redundant_with_win(self): 164 def test_linux_redundant_with_win(self):
152 self._assertOptimization({ 165 self._assertOptimization(
153 'platform/win': '1', 166 {
154 'platform/linux': '1', 167 'platform/win': '1',
155 }, { 168 'platform/linux': '1',
156 'platform/win': '1', 169 },
157 }) 170 {
171 'platform/win': '1',
172 })
158 173
159 def test_covers_mac_win_linux(self): 174 def test_covers_mac_win_linux(self):
160 self._assertOptimization({ 175 self._assertOptimization(
161 'platform/mac': '1', 176 {
162 'platform/win': '1', 177 'platform/mac': '1',
163 'platform/linux': '1', 178 'platform/win': '1',
164 '': None, 179 'platform/linux': '1',
165 }, { 180 '': None,
166 '': '1', 181 },
167 }) 182 {
183 '': '1',
184 })
168 185
169 def test_overwrites_root(self): 186 def test_overwrites_root(self):
170 self._assertOptimization({ 187 self._assertOptimization(
171 'platform/mac': '1', 188 {
172 'platform/win': '1', 189 'platform/mac': '1',
173 'platform/linux': '1', 190 'platform/win': '1',
174 '': '2', 191 'platform/linux': '1',
175 }, { 192 '': '2',
176 '': '1', 193 },
177 }) 194 {
195 '': '1',
196 })
178 197
179 def test_no_new_common_directory(self): 198 def test_no_new_common_directory(self):
180 self._assertOptimization({ 199 self._assertOptimization(
181 'platform/mac': '1', 200 {
182 'platform/linux': '1', 201 'platform/mac': '1',
183 '': '2', 202 'platform/linux': '1',
184 }, { 203 '': '2',
185 'platform/mac': '1', 204 },
186 'platform/linux': '1', 205 {
187 '': '2', 206 'platform/mac': '1',
188 }) 207 'platform/linux': '1',
208 '': '2',
209 })
189 210
190 def test_local_optimization(self): 211 def test_local_optimization(self):
191 self._assertOptimization({ 212 self._assertOptimization(
192 'platform/mac': '1', 213 {
193 'platform/linux': '1', 214 'platform/mac': '1',
194 'platform/linux-precise': '1', 215 'platform/linux': '1',
195 }, { 216 'platform/linux-precise': '1',
196 'platform/mac': '1', 217 },
197 'platform/linux': '1', 218 {
198 }) 219 'platform/mac': '1',
220 'platform/linux': '1',
221 })
199 222
200 def test_local_optimization_skipping_a_port_in_the_middle(self): 223 def test_local_optimization_skipping_a_port_in_the_middle(self):
201 self._assertOptimization({ 224 self._assertOptimization(
202 'platform/mac-snowleopard': '1', 225 {
203 'platform/win': '1', 226 'platform/mac-snowleopard': '1',
204 'platform/linux': '1', 227 'platform/win': '1',
205 'platform/linux-precise': '1', 228 'platform/linux': '1',
206 }, { 229 'platform/linux-precise': '1',
207 'platform/mac-snowleopard': '1', 230 },
208 'platform/win': '1', 231 {
209 }) 232 'platform/mac-snowleopard': '1',
233 'platform/win': '1',
234 })
210 235
211 def test_baseline_redundant_with_root(self): 236 def test_baseline_redundant_with_root(self):
212 self._assertOptimization({ 237 self._assertOptimization(
213 'platform/mac': '1', 238 {
214 'platform/win': '2', 239 'platform/mac': '1',
215 '': '2', 240 'platform/win': '2',
216 }, { 241 '': '2',
217 'platform/mac': '1', 242 },
218 '': '2', 243 {
219 }) 244 'platform/mac': '1',
245 '': '2',
246 })
220 247
221 def test_root_baseline_unused(self): 248 def test_root_baseline_unused(self):
222 self._assertOptimization({ 249 self._assertOptimization(
223 'platform/mac': '1', 250 {
224 'platform/win': '2', 251 'platform/mac': '1',
225 '': '3', 252 'platform/win': '2',
226 }, { 253 '': '3',
227 'platform/mac': '1', 254 },
228 'platform/win': '2', 255 {
229 }) 256 'platform/mac': '1',
257 'platform/win': '2',
258 })
230 259
231 def test_root_baseline_unused_and_non_existant(self): 260 def test_root_baseline_unused_and_non_existant(self):
232 self._assertOptimization({ 261 self._assertOptimization(
233 'platform/mac': '1', 262 {
234 'platform/win': '2', 263 'platform/mac': '1',
235 }, { 264 'platform/win': '2',
236 'platform/mac': '1', 265 },
237 'platform/win': '2', 266 {
238 }) 267 'platform/mac': '1',
268 'platform/win': '2',
269 })
239 270
240 def test_virtual_root_redundant_with_actual_root(self): 271 def test_virtual_root_redundant_with_actual_root(self):
241 self._assertOptimization({ 272 self._assertOptimization(
242 'virtual/gpu/fast/canvas': '2', 273 {
243 'fast/canvas': '2', 274 'virtual/gpu/fast/canvas': '2',
244 }, { 275 'fast/canvas': '2',
245 'virtual/gpu/fast/canvas': None, 276 },
246 'fast/canvas': '2', 277 {
247 }, baseline_dirname='virtual/gpu/fast/canvas') 278 'virtual/gpu/fast/canvas': None,
279 'fast/canvas': '2',
280 },
281 baseline_dirname='virtual/gpu/fast/canvas')
248 282
249 def test_virtual_root_redundant_with_ancestors(self): 283 def test_virtual_root_redundant_with_ancestors(self):
250 self._assertOptimization({ 284 self._assertOptimization(
251 'virtual/gpu/fast/canvas': '2', 285 {
252 'platform/mac/fast/canvas': '2', 286 'virtual/gpu/fast/canvas': '2',
253 'platform/win/fast/canvas': '2', 287 'platform/mac/fast/canvas': '2',
254 }, { 288 'platform/win/fast/canvas': '2',
255 'virtual/gpu/fast/canvas': None, 289 },
256 'fast/canvas': '2', 290 {
257 }, baseline_dirname='virtual/gpu/fast/canvas') 291 'virtual/gpu/fast/canvas': None,
292 'fast/canvas': '2',
293 },
294 baseline_dirname='virtual/gpu/fast/canvas')
258 295
259 def test_virtual_root_redundant_with_ancestors_skip_scm_commands(self): 296 def test_virtual_root_redundant_with_ancestors_skip_scm_commands(self):
260 self._assertOptimization({ 297 self._assertOptimization(
261 'virtual/gpu/fast/canvas': '2', 298 {
262 'platform/mac/fast/canvas': '2', 299 'virtual/gpu/fast/canvas': '2',
263 'platform/win/fast/canvas': '2', 300 'platform/mac/fast/canvas': '2',
264 }, { 301 'platform/win/fast/canvas': '2',
265 'virtual/gpu/fast/canvas': None, 302 },
266 'fast/canvas': '2', 303 {
267 }, 304 'virtual/gpu/fast/canvas': None,
305 'fast/canvas': '2',
306 },
268 baseline_dirname='virtual/gpu/fast/canvas', 307 baseline_dirname='virtual/gpu/fast/canvas',
269 expected_files_to_delete=[ 308 expected_files_to_delete=[
270 '/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast/canv as/mock-baseline-expected.txt', 309 '/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast/ canvas/mock-baseline-expected.txt',
271 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast/can vas/mock-baseline-expected.txt', 310 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast /canvas/mock-baseline-expected.txt',
272 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast/can vas/mock-baseline-expected.txt', 311 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast /canvas/mock-baseline-expected.txt',
273 ]) 312 ])
274 313
275 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n ot_in_scm(self): 314 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n ot_in_scm(self):
276 self._assertOptimization({ 315 self._assertOptimization(
277 'virtual/gpu/fast/canvas': '2', 316 {
278 'platform/mac/fast/canvas': '2', 317 'virtual/gpu/fast/canvas': '2',
279 'platform/win/fast/canvas': '2', 318 'platform/mac/fast/canvas': '2',
280 }, { 319 'platform/win/fast/canvas': '2',
281 'virtual/gpu/fast/canvas': None, 320 },
282 'fast/canvas': '2', 321 {
283 }, 322 'virtual/gpu/fast/canvas': None,
323 'fast/canvas': '2',
324 },
284 baseline_dirname='virtual/gpu/fast/canvas', 325 baseline_dirname='virtual/gpu/fast/canvas',
285 expected_files_to_delete=[ 326 expected_files_to_delete=[
286 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast/can vas/mock-baseline-expected.txt', 327 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast /canvas/mock-baseline-expected.txt',
287 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast/can vas/mock-baseline-expected.txt', 328 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast /canvas/mock-baseline-expected.txt',
288 ], 329 ],
289 host=MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebK it/LayoutTests/virtual/gpu/fast/canvas/mock-baseline-expected.txt']))) 330 host=MockHost(scm=ExcludingMockSCM(
331 ['/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast /canvas/mock-baseline-expected.txt'])))
290 332
291 def test_virtual_root_not_redundant_with_ancestors(self): 333 def test_virtual_root_not_redundant_with_ancestors(self):
292 self._assertOptimization({ 334 self._assertOptimization(
293 'virtual/gpu/fast/canvas': '2', 335 {
294 'platform/mac/fast/canvas': '1', 336 'virtual/gpu/fast/canvas': '2',
295 }, { 337 'platform/mac/fast/canvas': '1',
296 'virtual/gpu/fast/canvas': '2', 338 },
297 'platform/mac/fast/canvas': '1', 339 {
298 }, baseline_dirname='virtual/gpu/fast/canvas') 340 'virtual/gpu/fast/canvas': '2',
341 'platform/mac/fast/canvas': '1',
342 },
343 baseline_dirname='virtual/gpu/fast/canvas')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698