blob: b4f62d6d56a5fbe0650f6a6b4a3db271bd99ba24 [file] [log] [blame]
mblighbe630eb2008-08-01 16:41:48 +00001#!/usr/bin/python
2#
3# Copyright 2008 Google Inc. All Rights Reserved.
4
5"""Test for atest."""
6
7import unittest, os, sys, StringIO
8
9import common
10from autotest_lib.cli import cli_mock
11
12
13class main_unittest(cli_mock.cli_unittest):
14 def _test_help(self, argv, out_words_ok, err_words_ok):
15 saved_outputs = None
16 for help in ['-h', '--help', 'help']:
17 outputs = self.run_cmd(argv + [help], exit_code=0,
18 out_words_ok=out_words_ok,
19 err_words_ok=err_words_ok)
20 if not saved_outputs:
21 saved_outputs = outputs
22 else:
23 self.assertEqual(outputs, saved_outputs)
24
25
26 def test_main_help(self):
27 """Main help level"""
28 self._test_help(argv=['atest'],
showardfb64e6a2009-04-22 21:01:18 +000029 out_words_ok=['atest [acl|host|job|label|atomicgroup'
30 '|test|user] [action] [options]'],
mblighbe630eb2008-08-01 16:41:48 +000031 err_words_ok=[])
32
33
34 def test_main_help_topic(self):
35 """Topic level help"""
36 self._test_help(argv=['atest', 'host'],
mbligh901aaa92008-08-27 19:34:20 +000037 out_words_ok=['atest host ',
showardfb64e6a2009-04-22 21:01:18 +000038 '[create|delete|list|stat|mod|jobs]'
39 ' [options]'],
mblighbe630eb2008-08-01 16:41:48 +000040 err_words_ok=[])
41
42
43 def test_main_help_action(self):
44 """Action level help"""
45 self._test_help(argv=['atest:', 'host', 'mod'],
mbligh901aaa92008-08-27 19:34:20 +000046 out_words_ok=['atest host mod [options]'],
mblighbe630eb2008-08-01 16:41:48 +000047 err_words_ok=[])
48
49
50 def test_main_no_topic(self):
51 self.run_cmd(['atest'], exit_code=1,
mbligh901aaa92008-08-27 19:34:20 +000052 out_words_ok=['atest '
showardfb64e6a2009-04-22 21:01:18 +000053 '[acl|host|job|label|atomicgroup|test|user] '
mblighbe630eb2008-08-01 16:41:48 +000054 '[action] [options]'],
55 err_words_ok=['No topic argument'])
56
57
58 def test_main_bad_topic(self):
59 self.run_cmd(['atest', 'bad_topic'], exit_code=1,
showardfb64e6a2009-04-22 21:01:18 +000060 out_words_ok=['atest [acl|host|job|label|atomicgroup'
61 '|test|user] [action] [options]'],
mblighbe630eb2008-08-01 16:41:48 +000062 err_words_ok=['Invalid topic bad_topic\n'])
63
64
65 def test_main_bad_action(self):
66 self.run_cmd(['atest', 'host', 'bad_action'], exit_code=1,
showardfb64e6a2009-04-22 21:01:18 +000067 out_words_ok=['atest host [create|delete|list|stat|'
68 'mod|jobs] [options]'],
mblighbe630eb2008-08-01 16:41:48 +000069 err_words_ok=['Invalid action bad_action'])
70
71
72if __name__ == '__main__':
73 unittest.main()