blob: dbc2549f6da8329c9e6171edc6b4cf1dd4fda503 [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'],
mbligh901aaa92008-08-27 19:34:20 +000029 out_words_ok=['atest [acl|host|job|label|test|user] '
mblighbe630eb2008-08-01 16:41:48 +000030 '[action] [options]'],
31 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 ',
mblighbe630eb2008-08-01 16:41:48 +000038 '[create|delete|list|stat|mod|jobs] [options]'],
39 err_words_ok=[])
40
41
42 def test_main_help_action(self):
43 """Action level help"""
44 self._test_help(argv=['atest:', 'host', 'mod'],
mbligh901aaa92008-08-27 19:34:20 +000045 out_words_ok=['atest host mod [options]'],
mblighbe630eb2008-08-01 16:41:48 +000046 err_words_ok=[])
47
48
49 def test_main_no_topic(self):
50 self.run_cmd(['atest'], exit_code=1,
mbligh901aaa92008-08-27 19:34:20 +000051 out_words_ok=['atest '
mbligh76dced82008-08-11 23:46:57 +000052 '[acl|host|job|label|test|user] '
mblighbe630eb2008-08-01 16:41:48 +000053 '[action] [options]'],
54 err_words_ok=['No topic argument'])
55
56
57 def test_main_bad_topic(self):
58 self.run_cmd(['atest', 'bad_topic'], exit_code=1,
mbligh901aaa92008-08-27 19:34:20 +000059 out_words_ok=['atest [acl|host|job|'
mbligh76dced82008-08-11 23:46:57 +000060 'label|test|user] [action] [options]'],
mblighbe630eb2008-08-01 16:41:48 +000061 err_words_ok=['Invalid topic bad_topic\n'])
62
63
64 def test_main_bad_action(self):
65 self.run_cmd(['atest', 'host', 'bad_action'], exit_code=1,
mbligh901aaa92008-08-27 19:34:20 +000066 out_words_ok=['atest host '
mblighbe630eb2008-08-01 16:41:48 +000067 '[create|delete|list|stat|mod|jobs] [options]'],
68 err_words_ok=['Invalid action bad_action'])
69
70
71if __name__ == '__main__':
72 unittest.main()