mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2008 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Test for atest.""" |
| 6 | |
| 7 | import unittest, os, sys, StringIO |
| 8 | |
| 9 | import common |
| 10 | from autotest_lib.cli import cli_mock |
| 11 | |
| 12 | |
| 13 | class 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'], |
showard | fb64e6a | 2009-04-22 21:01:18 +0000 | [diff] [blame] | 29 | out_words_ok=['atest [acl|host|job|label|atomicgroup' |
| 30 | '|test|user] [action] [options]'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 31 | err_words_ok=[]) |
| 32 | |
| 33 | |
| 34 | def test_main_help_topic(self): |
| 35 | """Topic level help""" |
| 36 | self._test_help(argv=['atest', 'host'], |
mbligh | 901aaa9 | 2008-08-27 19:34:20 +0000 | [diff] [blame] | 37 | out_words_ok=['atest host ', |
showard | fb64e6a | 2009-04-22 21:01:18 +0000 | [diff] [blame] | 38 | '[create|delete|list|stat|mod|jobs]' |
| 39 | ' [options]'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 40 | err_words_ok=[]) |
| 41 | |
| 42 | |
| 43 | def test_main_help_action(self): |
| 44 | """Action level help""" |
| 45 | self._test_help(argv=['atest:', 'host', 'mod'], |
mbligh | 901aaa9 | 2008-08-27 19:34:20 +0000 | [diff] [blame] | 46 | out_words_ok=['atest host mod [options]'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 47 | err_words_ok=[]) |
| 48 | |
| 49 | |
| 50 | def test_main_no_topic(self): |
| 51 | self.run_cmd(['atest'], exit_code=1, |
mbligh | 901aaa9 | 2008-08-27 19:34:20 +0000 | [diff] [blame] | 52 | out_words_ok=['atest ' |
showard | fb64e6a | 2009-04-22 21:01:18 +0000 | [diff] [blame] | 53 | '[acl|host|job|label|atomicgroup|test|user] ' |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 54 | '[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, |
showard | fb64e6a | 2009-04-22 21:01:18 +0000 | [diff] [blame] | 60 | out_words_ok=['atest [acl|host|job|label|atomicgroup' |
| 61 | '|test|user] [action] [options]'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 62 | 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, |
showard | fb64e6a | 2009-04-22 21:01:18 +0000 | [diff] [blame] | 67 | out_words_ok=['atest host [create|delete|list|stat|' |
| 68 | 'mod|jobs] [options]'], |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 69 | err_words_ok=['Invalid action bad_action']) |
| 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | unittest.main() |