1#!/usr/bin/python 2# 3# Copyright 2008 Google Inc. All Rights Reserved. 4 5"""Test for atest.""" 6 7import unittest 8 9import common 10from autotest_lib.cli import cli_mock 11 12ATEST_USAGE_STRING = ('atest [acl|host|job|label|shard|test|user|' 13 'server] [action] [options]') 14 15class main_unittest(cli_mock.cli_unittest): 16 """Unittest for atest command. 17 """ 18 19 def _test_help(self, argv, out_words_ok, err_words_ok): 20 """Test help output. 21 22 @param argv: A list of argument. 23 @param out_words_ok: Expected output. 24 @param err_words_ok: Expected output when input arguments are invalid. 25 """ 26 saved_outputs = None 27 for help in ['-h', '--help', 'help']: 28 outputs = self.run_cmd(argv + [help], exit_code=0, 29 out_words_ok=out_words_ok, 30 err_words_ok=err_words_ok) 31 if not saved_outputs: 32 saved_outputs = outputs 33 else: 34 self.assertEqual(outputs, saved_outputs) 35 36 37 def test_main_help(self): 38 """Main help level""" 39 self._test_help(argv=['atest'], 40 out_words_ok=[ATEST_USAGE_STRING], 41 err_words_ok=[]) 42 43 44 def test_main_help_topic(self): 45 """Topic level help""" 46 self._test_help(argv=['atest', 'host'], 47 out_words_ok=['atest host ', 48 '[create|delete|list|stat|mod|jobs|' 49 'rename|migrate] [options]'], 50 err_words_ok=[]) 51 52 53 def test_main_help_action(self): 54 """Action level help""" 55 self._test_help(argv=['atest:', 'host', 'mod'], 56 out_words_ok=['atest host mod [options]'], 57 err_words_ok=[]) 58 59 60 def test_main_no_topic(self): 61 """Test output when no topic is specified.""" 62 self.run_cmd(['atest'], exit_code=1, 63 out_words_ok=[ATEST_USAGE_STRING], 64 err_words_ok=['No topic argument']) 65 66 67 def test_main_bad_topic(self): 68 """Test output when an invalid topic is specified.""" 69 self.run_cmd(['atest', 'bad_topic'], exit_code=1, 70 out_words_ok=[ATEST_USAGE_STRING], 71 err_words_ok=['Invalid topic bad_topic\n']) 72 73 74 def test_main_bad_action(self): 75 """Test output when an invalid action is specified.""" 76 self.run_cmd(['atest', 'host', 'bad_action'], exit_code=1, 77 out_words_ok=['atest host [create|delete|list|stat|' 78 'mod|jobs|rename|migrate] [options]'], 79 err_words_ok=['Invalid action bad_action']) 80 81 82if __name__ == '__main__': 83 unittest.main() 84