OLD | NEW |
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 raise Exception("File is not SCM managed: " + origin) | 58 raise Exception("File is not SCM managed: " + origin) |
59 return MockSCM.move(self, origin, destination) | 59 return MockSCM.move(self, origin, destination) |
60 | 60 |
61 | 61 |
62 class BaselineOptimizerTest(unittest.TestCase): | 62 class BaselineOptimizerTest(unittest.TestCase): |
63 def test_move_baselines(self): | 63 def test_move_baselines(self): |
64 host = MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit
/LayoutTests/platform/mac/another/test-expected.txt'])) | 64 host = MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit
/LayoutTests/platform/mac/another/test-expected.txt'])) |
65 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/platform/win/another/test-expected.txt', 'result A') | 65 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/platform/win/another/test-expected.txt', 'result A') |
66 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/platform/mac/another/test-expected.txt', 'result A') | 66 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/platform/mac/another/test-expected.txt', 'result A') |
67 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') | 67 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') |
68 baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_
names()) | 68 baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_
names(), skip_scm_commands=False) |
69 baseline_optimizer._move_baselines('another/test-expected.txt', { | 69 baseline_optimizer._move_baselines('another/test-expected.txt', { |
70 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', | 70 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', |
71 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', | 71 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', |
72 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', | 72 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', |
73 }, { | 73 }, { |
74 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', | 74 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', |
75 }) | 75 }) |
76 self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/third_
party/WebKit/LayoutTests/another/test-expected.txt'), 'result A') | 76 self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/third_
party/WebKit/LayoutTests/another/test-expected.txt'), 'result A') |
77 | 77 |
78 def _assertOptimization(self, results_by_directory, expected_new_results_by_
directory, baseline_dirname=''): | 78 def test_move_baselines_skip_scm_commands(self): |
| 79 host = MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit
/LayoutTests/platform/mac/another/test-expected.txt'])) |
| 80 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/platform/win/another/test-expected.txt', 'result A') |
| 81 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/platform/mac/another/test-expected.txt', 'result A') |
| 82 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') |
| 83 baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_
names(), skip_scm_commands=True) |
| 84 baseline_optimizer._move_baselines('another/test-expected.txt', { |
| 85 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', |
| 86 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', |
| 87 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', |
| 88 }, { |
| 89 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb
', |
| 90 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', |
| 91 }) |
| 92 self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/third_
party/WebKit/LayoutTests/another/test-expected.txt'), 'result A') |
| 93 |
| 94 self.assertEqual(baseline_optimizer._files_to_delete, [ |
| 95 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/
test-expected.txt', |
| 96 ]) |
| 97 |
| 98 self.assertEqual(baseline_optimizer._files_to_add, [ |
| 99 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected
.txt', |
| 100 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/anothe
r/test-expected.txt', |
| 101 ]) |
| 102 |
| 103 def _assertOptimization(self, results_by_directory, expected_new_results_by_
directory, baseline_dirname='', expected_files_to_delete=None): |
79 host = MockHost() | 104 host = MockHost() |
80 fs = host.filesystem | 105 fs = host.filesystem |
81 webkit_base = WebKitFinder(fs).webkit_base() | 106 webkit_base = WebKitFinder(fs).webkit_base() |
82 baseline_name = 'mock-baseline-expected.txt' | 107 baseline_name = 'mock-baseline-expected.txt' |
83 | 108 |
84 for dirname, contents in results_by_directory.items(): | 109 for dirname, contents in results_by_directory.items(): |
85 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 110 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
86 fs.write_binary_file(path, contents) | 111 fs.write_binary_file(path, contents) |
87 | 112 |
88 baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_
names()) | 113 baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_
names(), skip_scm_commands=expected_files_to_delete is not None) |
89 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba
seline_name))) | 114 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba
seline_name))) |
90 | 115 |
91 for dirname, contents in expected_new_results_by_directory.items(): | 116 for dirname, contents in expected_new_results_by_directory.items(): |
92 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 117 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
93 if contents is None: | 118 if contents is None: |
94 self.assertFalse(fs.exists(path)) | 119 self.assertTrue(not fs.exists(path) or path in baseline_optimize
r._files_to_delete) |
95 else: | 120 else: |
96 self.assertEqual(fs.read_binary_file(path), contents) | 121 self.assertEqual(fs.read_binary_file(path), contents) |
97 | 122 |
98 # Check that the files that were in the original set have been deleted w
here necessary. | 123 # Check that the files that were in the original set have been deleted w
here necessary. |
99 for dirname in results_by_directory: | 124 for dirname in results_by_directory: |
100 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 125 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
101 if not dirname in expected_new_results_by_directory: | 126 if not dirname in expected_new_results_by_directory: |
102 self.assertFalse(fs.exists(path)) | 127 self.assertTrue(not fs.exists(path) or path in baseline_optimize
r._files_to_delete) |
| 128 |
| 129 if expected_files_to_delete: |
| 130 self.assertEqual(baseline_optimizer._files_to_delete, expected_files
_to_delete) |
103 | 131 |
104 def test_linux_redundant_with_win(self): | 132 def test_linux_redundant_with_win(self): |
105 self._assertOptimization({ | 133 self._assertOptimization({ |
106 'platform/win': '1', | 134 'platform/win': '1', |
107 'platform/linux': '1', | 135 'platform/linux': '1', |
108 }, { | 136 }, { |
109 'platform/win': '1', | 137 'platform/win': '1', |
110 }) | 138 }) |
111 | 139 |
112 def test_covers_mac_win_linux(self): | 140 def test_covers_mac_win_linux(self): |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 def test_virtual_root_redundant_with_ancestors(self): | 230 def test_virtual_root_redundant_with_ancestors(self): |
203 self._assertOptimization({ | 231 self._assertOptimization({ |
204 'virtual/softwarecompositing': '2', | 232 'virtual/softwarecompositing': '2', |
205 'platform/mac/compositing': '2', | 233 'platform/mac/compositing': '2', |
206 'platform/win/compositing': '2', | 234 'platform/win/compositing': '2', |
207 }, { | 235 }, { |
208 'virtual/softwarecompositing': None, | 236 'virtual/softwarecompositing': None, |
209 'compositing': '2', | 237 'compositing': '2', |
210 }, baseline_dirname='virtual/softwarecompositing') | 238 }, baseline_dirname='virtual/softwarecompositing') |
211 | 239 |
| 240 def test_virtual_root_redundant_with_ancestors_skip_scm_commands(self): |
| 241 self._assertOptimization({ |
| 242 'virtual/softwarecompositing': '2', |
| 243 'platform/mac/compositing': '2', |
| 244 'platform/win/compositing': '2', |
| 245 }, { |
| 246 'virtual/softwarecompositing': None, |
| 247 'compositing': '2', |
| 248 }, |
| 249 baseline_dirname='virtual/softwarecompositing', |
| 250 expected_files_to_delete=[ |
| 251 '/mock-checkout/third_party/WebKit/LayoutTests/virtual/softwarecompo
siting/mock-baseline-expected.txt', |
| 252 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/composit
ing/mock-baseline-expected.txt', |
| 253 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/composit
ing/mock-baseline-expected.txt', |
| 254 ]) |
| 255 |
212 def test_virtual_root_not_redundant_with_ancestors(self): | 256 def test_virtual_root_not_redundant_with_ancestors(self): |
213 self._assertOptimization({ | 257 self._assertOptimization({ |
214 'virtual/softwarecompositing': '2', | 258 'virtual/softwarecompositing': '2', |
215 'platform/mac/compositing': '1', | 259 'platform/mac/compositing': '1', |
216 }, { | 260 }, { |
217 'virtual/softwarecompositing': '2', | 261 'virtual/softwarecompositing': '2', |
218 'platform/mac/compositing': '1', | 262 'platform/mac/compositing': '1', |
219 }, baseline_dirname='virtual/softwarecompositing') | 263 }, baseline_dirname='virtual/softwarecompositing') |
OLD | NEW |