| OLD | NEW |
| 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 optparse |
| 6 |
| 5 from webkitpy.common.system.outputcapture import OutputCapture | 7 from webkitpy.common.system.outputcapture import OutputCapture |
| 6 from webkitpy.tool.commands.optimize_baselines import OptimizeBaselines | 8 from webkitpy.tool.commands.optimize_baselines import OptimizeBaselines |
| 7 from webkitpy.tool.commands.rebaseline_unittest import BaseTestCase | 9 from webkitpy.tool.commands.rebaseline_unittest import BaseTestCase |
| 8 from webkitpy.tool.mock_tool import MockOptions | |
| 9 | 10 |
| 10 | 11 |
| 11 class TestOptimizeBaselines(BaseTestCase): | 12 class TestOptimizeBaselines(BaseTestCase): |
| 12 command_constructor = OptimizeBaselines | 13 command_constructor = OptimizeBaselines |
| 13 | 14 |
| 14 def _write_test_file(self, port, path, contents): | 15 def _write_test_file(self, port, path, contents): |
| 15 abs_path = self.tool.filesystem.join(port.layout_tests_dir(), path) | 16 abs_path = self.tool.filesystem.join(port.layout_tests_dir(), path) |
| 16 self.tool.filesystem.write_text_file(abs_path, contents) | 17 self.tool.filesystem.write_text_file(abs_path, contents) |
| 17 | 18 |
| 18 def setUp(self): | 19 def setUp(self): |
| 19 super(TestOptimizeBaselines, self).setUp() | 20 super(TestOptimizeBaselines, self).setUp() |
| 20 | 21 |
| 21 def test_modify_scm(self): | 22 def test_modify_scm(self): |
| 22 test_port = self.tool.port_factory.get('test') | 23 test_port = self.tool.port_factory.get('test') |
| 23 self._write_test_file(test_port, 'another/test.html', "Dummy test conten
ts") | 24 self._write_test_file(test_port, 'another/test.html', "Dummy test conten
ts") |
| 24 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.txt', "result A") | 25 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.txt', "result A") |
| 25 self._write_test_file(test_port, 'another/test-expected.txt', "result A"
) | 26 self._write_test_file(test_port, 'another/test-expected.txt', "result A"
) |
| 26 | 27 |
| 27 OutputCapture().assert_outputs(self, self.command.execute, args=[ | 28 OutputCapture().assert_outputs(self, self.command.execute, args=[ |
| 28 MockOptions(suffixes='txt', no_modify_scm=False, platform='test-mac-
mac10.10'), | 29 optparse.Values({'suffixes': 'txt', 'no_modify_scm': False, 'platfor
m': 'test-mac-mac10.10'}), |
| 29 ['another/test.html'], | 30 ['another/test.html'], |
| 30 self.tool, | 31 self.tool, |
| 31 ], expected_stdout='{"add": [], "remove-lines": [], "delete": []}\n') | 32 ], expected_stdout='{"add": [], "remove-lines": [], "delete": []}\n') |
| 32 | 33 |
| 33 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( | 34 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 34 test_port.layout_tests_dir(), 'platform/test-mac-mac10.10/another/te
st-expected.txt'))) | 35 test_port.layout_tests_dir(), 'platform/test-mac-mac10.10/another/te
st-expected.txt'))) |
| 35 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( | 36 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 36 test_port.layout_tests_dir(), 'another/test-expected.txt'))) | 37 test_port.layout_tests_dir(), 'another/test-expected.txt'))) |
| 37 | 38 |
| 38 def test_no_modify_scm(self): | 39 def test_no_modify_scm(self): |
| 39 test_port = self.tool.port_factory.get('test') | 40 test_port = self.tool.port_factory.get('test') |
| 40 self._write_test_file(test_port, 'another/test.html', "Dummy test conten
ts") | 41 self._write_test_file(test_port, 'another/test.html', "Dummy test conten
ts") |
| 41 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.txt', "result A") | 42 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.txt', "result A") |
| 42 self._write_test_file(test_port, 'another/test-expected.txt', "result A"
) | 43 self._write_test_file(test_port, 'another/test-expected.txt', "result A"
) |
| 43 | 44 |
| 44 OutputCapture().assert_outputs(self, self.command.execute, args=[ | 45 OutputCapture().assert_outputs(self, self.command.execute, args=[ |
| 45 MockOptions(suffixes='txt', no_modify_scm=True, platform='test-mac-m
ac10.10'), | 46 optparse.Values({'suffixes': 'txt', 'no_modify_scm': True, 'platform
': 'test-mac-mac10.10'}), |
| 46 ['another/test.html'], | 47 ['another/test.html'], |
| 47 self.tool, | 48 self.tool, |
| 48 ], expected_stdout='{"add": [], "remove-lines": [], "delete": ["/test.ch
eckout/LayoutTests/platform/test-mac-mac10.10/another/test-expected.txt"]}\n') | 49 ], expected_stdout='{"add": [], "remove-lines": [], "delete": ["/test.ch
eckout/LayoutTests/platform/test-mac-mac10.10/another/test-expected.txt"]}\n') |
| 49 | 50 |
| 50 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( | 51 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 51 test_port.layout_tests_dir(), 'platform/mac/another/test-expected.tx
t'))) | 52 test_port.layout_tests_dir(), 'platform/mac/another/test-expected.tx
t'))) |
| 52 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( | 53 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 53 test_port.layout_tests_dir(), 'another/test-expected.txt'))) | 54 test_port.layout_tests_dir(), 'another/test-expected.txt'))) |
| 54 | 55 |
| 55 def test_optimize_all_suffixes_by_default(self): | 56 def test_optimize_all_suffixes_by_default(self): |
| 56 test_port = self.tool.port_factory.get('test') | 57 test_port = self.tool.port_factory.get('test') |
| 57 self._write_test_file(test_port, 'another/test.html', "Dummy test conten
ts") | 58 self._write_test_file(test_port, 'another/test.html', "Dummy test conten
ts") |
| 58 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.txt', "result A") | 59 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.txt', "result A") |
| 59 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.png', "result A png") | 60 self._write_test_file(test_port, 'platform/test-mac-mac10.10/another/tes
t-expected.png', "result A png") |
| 60 self._write_test_file(test_port, 'another/test-expected.txt', "result A"
) | 61 self._write_test_file(test_port, 'another/test-expected.txt', "result A"
) |
| 61 self._write_test_file(test_port, 'another/test-expected.png', "result A
png") | 62 self._write_test_file(test_port, 'another/test-expected.png', "result A
png") |
| 62 | 63 |
| 63 try: | 64 try: |
| 64 oc = OutputCapture() | 65 oc = OutputCapture() |
| 65 oc.capture_output() | 66 oc.capture_output() |
| 66 self.command.execute(MockOptions(suffixes='txt,wav,png', no_modify_s
cm=True, platform='test-mac-mac10.10'), | 67 self.command.execute( |
| 67 ['another/test.html'], | 68 optparse.Values({'suffixes': 'txt,wav,png', 'no_modify_scm': Tru
e, 'platform': 'test-mac-mac10.10'}), |
| 68 self.tool) | 69 ['another/test.html'], |
| 70 self.tool) |
| 69 finally: | 71 finally: |
| 70 out, _, _ = oc.restore_output() | 72 out, _, _ = oc.restore_output() |
| 71 | 73 |
| 72 self.assertEquals(out, '{"add": [], "remove-lines": [], "delete": ["/tes
t.checkout/LayoutTests/platform/test-mac-mac10.10/another/test-expected.txt", "/
test.checkout/LayoutTests/platform/test-mac-mac10.10/another/test-expected.png"]
}\n') | 74 self.assertEquals(out, '{"add": [], "remove-lines": [], "delete": ["/tes
t.checkout/LayoutTests/platform/test-mac-mac10.10/another/test-expected.txt", "/
test.checkout/LayoutTests/platform/test-mac-mac10.10/another/test-expected.png"]
}\n') |
| 73 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( | 75 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 74 test_port.layout_tests_dir(), 'platform/mac/another/test-expected.tx
t'))) | 76 test_port.layout_tests_dir(), 'platform/mac/another/test-expected.tx
t'))) |
| 75 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( | 77 self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 76 test_port.layout_tests_dir(), 'platform/mac/another/test-expected.pn
g'))) | 78 test_port.layout_tests_dir(), 'platform/mac/another/test-expected.pn
g'))) |
| 77 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( | 79 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 78 test_port.layout_tests_dir(), 'another/test-expected.txt'))) | 80 test_port.layout_tests_dir(), 'another/test-expected.txt'))) |
| 79 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( | 81 self.assertTrue(self.tool.filesystem.exists(self.tool.filesystem.join( |
| 80 test_port.layout_tests_dir(), 'another/test-expected.png'))) | 82 test_port.layout_tests_dir(), 'another/test-expected.png'))) |
| OLD | NEW |