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

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

Issue 1839193004: Run auto-formatter (autopep8) on webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 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 17 matching lines...) Expand all
28 28
29 import unittest 29 import unittest
30 30
31 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer 31 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer
32 from webkitpy.common.checkout.scm.scm_mock import MockSCM 32 from webkitpy.common.checkout.scm.scm_mock import MockSCM
33 from webkitpy.common.host_mock import MockHost 33 from webkitpy.common.host_mock import MockHost
34 from webkitpy.common.webkit_finder import WebKitFinder 34 from webkitpy.common.webkit_finder import WebKitFinder
35 35
36 36
37 class ExcludingMockSCM(MockSCM): 37 class ExcludingMockSCM(MockSCM):
38
38 def __init__(self, exclusion_list, filesystem=None, executive=None): 39 def __init__(self, exclusion_list, filesystem=None, executive=None):
39 MockSCM.__init__(self, filesystem, executive) 40 MockSCM.__init__(self, filesystem, executive)
40 self._exclusion_list = exclusion_list 41 self._exclusion_list = exclusion_list
41 42
42 def exists(self, path): 43 def exists(self, path):
43 if path in self._exclusion_list: 44 if path in self._exclusion_list:
44 return False 45 return False
45 return MockSCM.exists(self, path) 46 return MockSCM.exists(self, path)
46 47
47 def delete(self, path): 48 def delete(self, path):
48 return self.delete_list([path]) 49 return self.delete_list([path])
49 50
50 def delete_list(self, paths): 51 def delete_list(self, paths):
51 for path in paths: 52 for path in paths:
52 if path in self._exclusion_list: 53 if path in self._exclusion_list:
53 raise Exception("File is not SCM managed: " + path) 54 raise Exception("File is not SCM managed: " + path)
54 return MockSCM.delete_list(self, paths) 55 return MockSCM.delete_list(self, paths)
55 56
56 def move(self, origin, destination): 57 def move(self, origin, destination):
57 if origin in self._exclusion_list: 58 if origin in self._exclusion_list:
58 raise Exception("File is not SCM managed: " + origin) 59 raise Exception("File is not SCM managed: " + origin)
59 return MockSCM.move(self, origin, destination) 60 return MockSCM.move(self, origin, destination)
60 61
61 62
62 class BaselineOptimizerTest(unittest.TestCase): 63 class BaselineOptimizerTest(unittest.TestCase):
64
63 def test_move_baselines(self): 65 def test_move_baselines(self):
64 host = MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit /LayoutTests/platform/mac/another/test-expected.txt'])) 66 host = MockHost(scm=ExcludingMockSCM(
67 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another /test-expected.txt']))
65 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]') 68 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]')
66 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/platform/win/another/test-expected.txt', 'result A') 69 host.filesystem.write_binary_file(
67 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/platform/mac/another/test-expected.txt', 'result A') 70 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A')
71 host.filesystem.write_binary_file(
72 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A')
68 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B') 73 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B')
69 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(), ho st.port_factory.all_port_names(), skip_scm_commands=False) 74 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(
75 ), host.port_factory.all_port_names(), skip_scm_commands=False)
70 baseline_optimizer._move_baselines('another/test-expected.txt', { 76 baseline_optimizer._move_baselines('another/test-expected.txt', {
71 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', 77 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa',
72 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', 78 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa',
73 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', 79 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb',
74 }, { 80 }, {
75 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', 81 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa',
76 }) 82 })
77 self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/third_ party/WebKit/LayoutTests/another/test-expected.txt'), 'result A') 83 self.assertEqual(host.filesystem.read_binary_file(
84 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt'), 'result A')
78 85
79 def test_move_baselines_skip_scm_commands(self): 86 def test_move_baselines_skip_scm_commands(self):
80 host = MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit /LayoutTests/platform/mac/another/test-expected.txt'])) 87 host = MockHost(scm=ExcludingMockSCM(
88 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another /test-expected.txt']))
81 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]') 89 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]')
82 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/platform/win/another/test-expected.txt', 'result A') 90 host.filesystem.write_binary_file(
83 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/platform/mac/another/test-expected.txt', 'result A') 91 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A')
92 host.filesystem.write_binary_file(
93 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A')
84 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B') 94 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B')
85 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(), ho st.port_factory.all_port_names(), skip_scm_commands=True) 95 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(
96 ), host.port_factory.all_port_names(), skip_scm_commands=True)
86 baseline_optimizer._move_baselines('another/test-expected.txt', { 97 baseline_optimizer._move_baselines('another/test-expected.txt', {
87 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', 98 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa',
88 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', 99 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa',
89 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', 100 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb',
90 }, { 101 }, {
91 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb ', 102 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb ',
92 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', 103 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa',
93 }) 104 })
94 self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/third_ party/WebKit/LayoutTests/another/test-expected.txt'), 'result A') 105 self.assertEqual(host.filesystem.read_binary_file(
106 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt'), 'result A')
95 107
96 self.assertEqual(baseline_optimizer._files_to_delete, [ 108 self.assertEqual(baseline_optimizer._files_to_delete, [
97 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 109 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt',
98 ]) 110 ])
99 111
100 self.assertEqual(baseline_optimizer._files_to_add, [ 112 self.assertEqual(baseline_optimizer._files_to_add, [
101 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt', 113 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt',
102 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/anothe r/test-expected.txt', 114 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/anothe r/test-expected.txt',
103 ]) 115 ])
104 116
105 def _assertOptimization(self, results_by_directory, expected_new_results_by_ directory, baseline_dirname='', expected_files_to_delete=None, host=None): 117 def _assertOptimization(self, results_by_directory, expected_new_results_by_ directory, baseline_dirname='', expected_files_to_delete=None, host=None):
106 if not host: 118 if not host:
107 host = MockHost() 119 host = MockHost()
108 fs = host.filesystem 120 fs = host.filesystem
109 webkit_base = WebKitFinder(fs).webkit_base() 121 webkit_base = WebKitFinder(fs).webkit_base()
110 baseline_name = 'mock-baseline-expected.txt' 122 baseline_name = 'mock-baseline-expected.txt'
111 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'), 123 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'),
112 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]') 124 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]')
113 125
114 for dirname, contents in results_by_directory.items(): 126 for dirname, contents in results_by_directory.items():
115 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) 127 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name)
116 fs.write_binary_file(path, contents) 128 fs.write_binary_file(path, contents)
117 129
118 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(), ho st.port_factory.all_port_names(), skip_scm_commands=expected_files_to_delete is not None) 130 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(
131 ), host.port_factory.all_port_names(), skip_scm_commands=expected_files_ to_delete is not None)
119 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba seline_name))) 132 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba seline_name)))
120 133
121 for dirname, contents in expected_new_results_by_directory.items(): 134 for dirname, contents in expected_new_results_by_directory.items():
122 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) 135 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name)
123 if contents is None: 136 if contents is None:
124 self.assertTrue(not fs.exists(path) or path in baseline_optimize r._files_to_delete) 137 self.assertTrue(not fs.exists(path) or path in baseline_optimize r._files_to_delete)
125 else: 138 else:
126 self.assertEqual(fs.read_binary_file(path), contents) 139 self.assertEqual(fs.read_binary_file(path), contents)
127 140
128 # Check that the files that were in the original set have been deleted w here necessary. 141 # Check that the files that were in the original set have been deleted w here necessary.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 self._assertOptimization({ 179 self._assertOptimization({
167 'platform/mac': '1', 180 'platform/mac': '1',
168 'platform/linux': '1', 181 'platform/linux': '1',
169 '': '2', 182 '': '2',
170 }, { 183 }, {
171 'platform/mac': '1', 184 'platform/mac': '1',
172 'platform/linux': '1', 185 'platform/linux': '1',
173 '': '2', 186 '': '2',
174 }) 187 })
175 188
176
177 def test_local_optimization(self): 189 def test_local_optimization(self):
178 self._assertOptimization({ 190 self._assertOptimization({
179 'platform/mac': '1', 191 'platform/mac': '1',
180 'platform/linux': '1', 192 'platform/linux': '1',
181 'platform/linux-precise': '1', 193 'platform/linux-precise': '1',
182 }, { 194 }, {
183 'platform/mac': '1', 195 'platform/mac': '1',
184 'platform/linux': '1', 196 'platform/linux': '1',
185 }) 197 })
186 198
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 257
246 def test_virtual_root_redundant_with_ancestors_skip_scm_commands(self): 258 def test_virtual_root_redundant_with_ancestors_skip_scm_commands(self):
247 self._assertOptimization({ 259 self._assertOptimization({
248 'virtual/gpu/fast/canvas': '2', 260 'virtual/gpu/fast/canvas': '2',
249 'platform/mac/fast/canvas': '2', 261 'platform/mac/fast/canvas': '2',
250 'platform/win/fast/canvas': '2', 262 'platform/win/fast/canvas': '2',
251 }, { 263 }, {
252 'virtual/gpu/fast/canvas': None, 264 'virtual/gpu/fast/canvas': None,
253 'fast/canvas': '2', 265 'fast/canvas': '2',
254 }, 266 },
255 baseline_dirname='virtual/gpu/fast/canvas', 267 baseline_dirname='virtual/gpu/fast/canvas',
256 expected_files_to_delete=[ 268 expected_files_to_delete=[
257 '/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast/canv as/mock-baseline-expected.txt', 269 '/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast/canv as/mock-baseline-expected.txt',
258 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast/can vas/mock-baseline-expected.txt', 270 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast/can vas/mock-baseline-expected.txt',
259 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast/can vas/mock-baseline-expected.txt', 271 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast/can vas/mock-baseline-expected.txt',
260 ]) 272 ])
261 273
262 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n ot_in_scm(self): 274 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n ot_in_scm(self):
263 self._assertOptimization({ 275 self._assertOptimization({
264 'virtual/gpu/fast/canvas': '2', 276 'virtual/gpu/fast/canvas': '2',
265 'platform/mac/fast/canvas': '2', 277 'platform/mac/fast/canvas': '2',
266 'platform/win/fast/canvas': '2', 278 'platform/win/fast/canvas': '2',
267 }, { 279 }, {
268 'virtual/gpu/fast/canvas': None, 280 'virtual/gpu/fast/canvas': None,
269 'fast/canvas': '2', 281 'fast/canvas': '2',
270 }, 282 },
271 baseline_dirname='virtual/gpu/fast/canvas', 283 baseline_dirname='virtual/gpu/fast/canvas',
272 expected_files_to_delete=[ 284 expected_files_to_delete=[
273 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast/can vas/mock-baseline-expected.txt', 285 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast/can vas/mock-baseline-expected.txt',
274 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast/can vas/mock-baseline-expected.txt', 286 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast/can vas/mock-baseline-expected.txt',
275 ], 287 ],
276 host=MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit/L ayoutTests/virtual/gpu/fast/canvas/mock-baseline-expected.txt']))) 288 host=MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebK it/LayoutTests/virtual/gpu/fast/canvas/mock-baseline-expected.txt'])))
277 289
278 def test_virtual_root_not_redundant_with_ancestors(self): 290 def test_virtual_root_not_redundant_with_ancestors(self):
279 self._assertOptimization({ 291 self._assertOptimization({
280 'virtual/gpu/fast/canvas': '2', 292 'virtual/gpu/fast/canvas': '2',
281 'platform/mac/fast/canvas': '1', 293 'platform/mac/fast/canvas': '1',
282 }, { 294 }, {
283 'virtual/gpu/fast/canvas': '2', 295 'virtual/gpu/fast/canvas': '2',
284 'platform/mac/fast/canvas': '1', 296 'platform/mac/fast/canvas': '1',
285 }, baseline_dirname='virtual/gpu/fast/canvas') 297 }, baseline_dirname='virtual/gpu/fast/canvas')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698