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