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