| 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 unittest | 5 import unittest |
| 6 | 6 |
| 7 from webkitpy.common.system.outputcapture import OutputCapture | 7 from webkitpy.common.system.outputcapture import OutputCapture |
| 8 from webkitpy.tool.webkit_patch import WebKitPatch | 8 from webkitpy.tool.webkit_patch import WebKitPatch |
| 9 | 9 |
| 10 | 10 |
| 11 class WebKitPatchTest(unittest.TestCase): | 11 class WebKitPatchTest(unittest.TestCase): |
| 12 | 12 |
| 13 def test_split_args_basic(self): | 13 def test_split_args_basic(self): |
| 14 self.assertEqual( | 14 self.assertEqual( |
| 15 WebKitPatch._split_command_name_from_args(['--global-option', 'comma
nd', '--option', 'arg']), | 15 WebKitPatch._split_command_name_from_args(['--global-option', 'comma
nd', '--option', 'arg']), |
| 16 ('command', ['--global-option', '--option', 'arg'])) | 16 ('command', ['--global-option', '--option', 'arg'])) |
| 17 | 17 |
| 18 def test_split_args_empty(self): | 18 def test_split_args_empty(self): |
| 19 self.assertEqual( | 19 self.assertEqual( |
| 20 WebKitPatch._split_command_name_from_args([]), | 20 WebKitPatch._split_command_name_from_args([]), |
| 21 (None, [])) | 21 (None, [])) |
| 22 | 22 |
| 23 def test_split_args_with_no_options(self): | 23 def test_split_args_with_no_options(self): |
| 24 self.assertEqual( | 24 self.assertEqual( |
| 25 WebKitPatch._split_command_name_from_args(['command', 'arg']), | 25 WebKitPatch._split_command_name_from_args(['command', 'arg']), |
| 26 ('command', ['arg'])) | 26 ('command', ['arg'])) |
| 27 | 27 |
| 28 def test_command_by_name(self): | 28 def test_command_by_name(self): |
| 29 tool = WebKitPatch() | 29 tool = WebKitPatch('path') |
| 30 self.assertEqual(tool.command_by_name('help').name, 'help') | 30 self.assertEqual(tool.command_by_name('help').name, 'help') |
| 31 self.assertIsNone(tool.command_by_name('non-existent')) | 31 self.assertIsNone(tool.command_by_name('non-existent')) |
| 32 | 32 |
| 33 def test_help(self): | 33 def test_help(self): |
| 34 oc = OutputCapture() | 34 oc = OutputCapture() |
| 35 oc.capture_output() | 35 oc.capture_output() |
| 36 tool = WebKitPatch() | 36 tool = WebKitPatch('path') |
| 37 tool.main(['tool', 'help']) | 37 tool.main(['tool', 'help']) |
| 38 out, err, logs = oc.restore_output() | 38 out, err, logs = oc.restore_output() |
| 39 self.assertTrue(out.startswith('Usage: ')) | 39 self.assertTrue(out.startswith('Usage: ')) |
| 40 self.assertEqual('', err) | 40 self.assertEqual('', err) |
| 41 self.assertEqual('', logs) | 41 self.assertEqual('', logs) |
| 42 | 42 |
| 43 def test_constructor_calls_bind_to_tool(self): | 43 def test_constructor_calls_bind_to_tool(self): |
| 44 tool = WebKitPatch() | 44 tool = WebKitPatch('path') |
| 45 self.assertEqual(tool.commands[0]._tool, tool) | 45 self.assertEqual(tool.commands[0]._tool, tool) |
| 46 self.assertEqual(tool.commands[1]._tool, tool) | 46 self.assertEqual(tool.commands[1]._tool, tool) |
| OLD | NEW |