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 3# found in the LICENSE file. 4 5import unittest 6 7from blinkpy.common.system.output_capture import OutputCapture 8from blinkpy.tool.blink_tool import BlinkTool 9 10 11class BlinkToolTest(unittest.TestCase): 12 13 def test_split_args_basic(self): 14 self.assertEqual( 15 BlinkTool._split_command_name_from_args(['--global-option', 'command', '--option', 'arg']), 16 ('command', ['--global-option', '--option', 'arg'])) 17 18 def test_split_args_empty(self): 19 self.assertEqual( 20 BlinkTool._split_command_name_from_args([]), 21 (None, [])) 22 23 def test_split_args_with_no_options(self): 24 self.assertEqual( 25 BlinkTool._split_command_name_from_args(['command', 'arg']), 26 ('command', ['arg'])) 27 28 def test_command_by_name(self): 29 tool = BlinkTool('path') 30 self.assertEqual(tool.command_by_name('help').name, 'help') 31 self.assertIsNone(tool.command_by_name('non-existent')) 32 33 def test_help_command(self): 34 oc = OutputCapture() 35 oc.capture_output() 36 tool = BlinkTool('path') 37 tool.main(['tool', 'help']) 38 out, err, logs = oc.restore_output() 39 self.assertTrue(out.startswith('Usage: ')) 40 self.assertEqual('', err) 41 self.assertEqual('', logs) 42 43 def test_help_argument(self): 44 oc = OutputCapture() 45 oc.capture_output() 46 tool = BlinkTool('path') 47 try: 48 tool.main(['tool', '--help']) 49 except SystemExit: 50 pass # optparse calls sys.exit after showing help. 51 finally: 52 out, err, logs = oc.restore_output() 53 self.assertTrue(out.startswith('Usage: ')) 54 self.assertEqual('', err) 55 self.assertEqual('', logs) 56