frontend.shared.rest_client: Fix reference to an undefined variable
[autotest-zwu.git] / cli / test.py
blobac1605a7a17c6850c6b4d4e28593d31c0710ae3f
2 # Copyright 2008 Google Inc. All Rights Reserved.
4 """
5 The test module contains the objects and methods used to
6 manage tests in Autotest.
8 The valid action is:
9 list: lists test(s)
11 The common options are:
12 --tlist / -T: file containing a list of tests
14 See topic_common.py for a High Level Design and Algorithm.
15 """
18 import os, sys
20 from autotest_lib.cli import topic_common, action_common
23 class test(topic_common.atest):
24 """Test class
25 atest test list <options>"""
26 usage_action = 'list'
27 topic = msg_topic = 'test'
28 msg_items = '[tests]'
30 def __init__(self):
31 """Add to the parser the options common to all the test actions"""
32 super(test, self).__init__()
34 self.parser.add_option('-T', '--tlist',
35 help='File listing the tests',
36 type='string',
37 default=None,
38 metavar='TEST_FLIST')
40 self.topic_parse_info = topic_common.item_parse_info(
41 attribute_name='tests',
42 filename_option='tlist',
43 use_leftover=True)
46 def get_items(self):
47 return self.tests
50 class test_help(test):
51 """Just here to get the atest logic working.
52 Usage is set by its parent"""
53 pass
56 class test_list(action_common.atest_list, test):
57 """atest test list [--description] [--experimental|--all] [<tests>]"""
58 def __init__(self):
59 super(test_list, self).__init__()
61 self.parser.add_option('-d', '--description',
62 help='Display the test descriptions',
63 action='store_true',
64 default=False)
65 self.parser.add_option('--all',
66 help='Display all the tests',
67 action='store_true',
68 default=False)
69 self.parser.add_option('-e', '--experimental',
70 help='Display the experimental tests only',
71 action='store_true',
72 default=False)
75 def parse(self):
76 (options, leftover) = super(test_list, self).parse()
78 if self.tests and (options.experimental or options.all):
79 self.invalid_syntax('Do not specify a test name with --all or '
80 '--experimental')
82 self.description = options.description
83 self.all = options.all
84 self.experimental = options.experimental
86 return (options, leftover)
89 def execute(self):
90 filters = {}
91 check_results = {}
92 if self.tests:
93 filters['name__in'] = self.tests
94 check_results['name__in'] = 'name'
96 if not self.all:
97 filters['experimental'] = self.experimental
98 check_results['experimental'] = None
100 return super(test_list, self).execute(op='get_tests',
101 filters=filters,
102 check_results=check_results)
105 def output(self, results):
106 keys = ['name', 'test_type', 'test_class']
108 if self.all:
109 keys.append('experimental')
111 if self.verbose:
112 keys.append('path')
114 if self.description:
115 keys.append('description')
117 super(test_list, self).output(results, keys)