Home | History | Annotate | Download | only in cli
      1 #!/usr/bin/python
      2 #
      3 # Copyright 2008 Google Inc. All Rights Reserved.
      4 
      5 """Tests for test."""
      6 
      7 import unittest
      8 
      9 import common
     10 from autotest_lib.cli import cli_mock
     11 from autotest_lib.client.common_lib import control_data
     12 
     13 CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
     14 SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
     15 
     16 class test_list_unittest(cli_mock.cli_unittest):
     17     values = [{u'description': u'unknown',
     18                u'test_type': CLIENT,
     19                u'test_class': u'Canned Test Sets',
     20                u'path': u'client/tests/test0/control',
     21                u'id': 138,
     22                u'name': u'test0',
     23                u'experimental': False},
     24               {u'description': u'unknown',
     25                u'test_type': SERVER,
     26                u'test_class': u'Kernel',
     27                u'path': u'server/tests/test1/control',
     28                u'id': 139,
     29                u'name': u'test1',
     30                u'experimental': False},
     31               {u'description': u'unknown',
     32                u'test_type': CLIENT,
     33                u'test_class': u'Canned Test Sets',
     34                u'path': u'client/tests/test2/control.readprofile',
     35                u'id': 140,
     36                u'name': u'test2',
     37                u'experimental': False},
     38               {u'description': u'unknown',
     39                u'test_type': SERVER,
     40                u'test_class': u'Canned Test Sets',
     41                u'path': u'server/tests/test3/control',
     42                u'id': 142,
     43                u'name': u'test3',
     44                u'experimental': False},
     45               {u'description': u'Random stuff to check that things are ok',
     46                u'test_type': CLIENT,
     47                u'test_class': u'Hardware',
     48                u'path': u'client/tests/test4/control.export',
     49                u'id': 143,
     50                u'name': u'test4',
     51                u'experimental': True}]
     52 
     53 
     54     def test_test_list_tests_default(self):
     55         self.run_cmd(argv=['atest', 'test', 'list'],
     56                      rpcs=[('get_tests', {'experimental': False},
     57                             True, self.values)],
     58                      out_words_ok=['test0', 'test1', 'test2',
     59                                    'test3', 'test4'],
     60                      out_words_no=['Random', 'control.export'])
     61 
     62 
     63     def test_test_list_tests_all(self):
     64         self.run_cmd(argv=['atest', 'test', 'list', '--all'],
     65                      rpcs=[('get_tests', {},
     66                             True, self.values)],
     67                      out_words_ok=['test0', 'test1', 'test2',
     68                                    'test3', 'test4'],
     69                      out_words_no=['Random', 'control.export'])
     70 
     71 
     72     def test_test_list_tests_exp(self):
     73         self.run_cmd(argv=['atest', 'test', 'list', '--experimental'],
     74                      rpcs=[('get_tests', {'experimental': True},
     75                             True,
     76                             [{u'description': u'Random stuff',
     77                               u'test_type': CLIENT,
     78                               u'test_class': u'Hardware',
     79                               u'path': u'client/tests/test4/control.export',
     80                               u'id': 143,
     81                               u'name': u'test4',
     82                               u'experimental': True}])],
     83                      out_words_ok=['test4'],
     84                      out_words_no=['Random', 'control.export'])
     85 
     86 
     87     def test_test_list_tests_select_one(self):
     88         filtered = [val for val in self.values if val['name'] in ['test3']]
     89         self.run_cmd(argv=['atest', 'test', 'list', 'test3'],
     90                      rpcs=[('get_tests', {'name__in': ['test3'],
     91                                           'experimental': False},
     92                             True, filtered)],
     93                      out_words_ok=['test3'],
     94                      out_words_no=['test0', 'test1', 'test2', 'test4',
     95                                    'unknown'])
     96 
     97 
     98     def test_test_list_tests_select_two(self):
     99         filtered = [val for val in self.values
    100                     if val['name'] in ['test3', 'test1']]
    101         self.run_cmd(argv=['atest', 'test', 'list', 'test3,test1'],
    102                      rpcs=[('get_tests', {'name__in': ['test1', 'test3'],
    103                                           'experimental': False},
    104                             True, filtered)],
    105                      out_words_ok=['test3', 'test1', SERVER],
    106                      out_words_no=['test0', 'test2', 'test4',
    107                                    'unknown', CLIENT])
    108 
    109 
    110     def test_test_list_tests_select_two_space(self):
    111         filtered = [val for val in self.values
    112                     if val['name'] in ['test3', 'test1']]
    113         self.run_cmd(argv=['atest', 'test', 'list', 'test3', 'test1'],
    114                      rpcs=[('get_tests', {'name__in': ['test1', 'test3'],
    115                                           'experimental': False},
    116                             True, filtered)],
    117                      out_words_ok=['test3', 'test1', SERVER],
    118                      out_words_no=['test0', 'test2', 'test4',
    119                                    'unknown', CLIENT])
    120 
    121 
    122     def test_test_list_tests_all_verbose(self):
    123         self.run_cmd(argv=['atest', 'test', 'list', '-v'],
    124                      rpcs=[('get_tests', {'experimental': False},
    125                             True, self.values)],
    126                      out_words_ok=['test0', 'test1', 'test2',
    127                                    'test3', 'test4', 'client/tests',
    128                                    'server/tests'],
    129                      out_words_no=['Random'])
    130 
    131 
    132     def test_test_list_tests_all_desc(self):
    133         self.run_cmd(argv=['atest', 'test', 'list', '-d'],
    134                      rpcs=[('get_tests', {'experimental': False},
    135                             True, self.values)],
    136                      out_words_ok=['test0', 'test1', 'test2',
    137                                    'test3', 'test4', 'unknown', 'Random'],
    138                      out_words_no=['client/tests', 'server/tests'])
    139 
    140 
    141     def test_test_list_tests_all_desc_verbose(self):
    142         self.run_cmd(argv=['atest', 'test', 'list', '-d', '-v'],
    143                      rpcs=[('get_tests', {'experimental': False},
    144                             True, self.values)],
    145                      out_words_ok=['test0', 'test1', 'test2',
    146                                    'test3', 'test4', 'client/tests',
    147                                    'server/tests', 'unknown', 'Random' ])
    148 
    149 
    150 if __name__ == '__main__':
    151     unittest.main()
    152