Package qm :: Package test :: Module suite
[hide private]
[frames] | no frames]

Source Code for Module qm.test.suite

  1  ######################################################################## 
  2  # 
  3  # File:   suite.py 
  4  # Author: Mark Mitchell 
  5  # Date:   11/05/2001 
  6  # 
  7  # Contents: 
  8  #   QMTest Suite class 
  9  # 
 10  # Copyright (c) 2001 by CodeSourcery, LLC.  All rights reserved.  
 11  # 
 12  # For license terms see the file COPYING. 
 13  # 
 14  ######################################################################## 
 15   
 16  ######################################################################## 
 17  # Imports 
 18  ######################################################################## 
 19   
 20  import qm 
 21  import qm.extension 
 22   
 23  ######################################################################## 
 24  # Classes 
 25  ######################################################################## 
 26   
27 -class Suite(qm.extension.Extension):
28 """A collection of tests. 29 30 A test suite is a collection of tests. The suite may contain other 31 suites by reference as well; all tests contained in these contained 32 suites are considered contained in the containing suite as well.""" 33 34 arguments = [ 35 ] 36 37 kind = "suite" 38 39 EXTRA_ID = "qmtest_id" 40 """The name of the extra keyword argument to '__init__' that 41 specifies the name of the test or resource.""" 42 43 EXTRA_DATABASE = "qmtest_database" 44 """The name of the extra keyword argument to '__init__' that 45 specifies the database containing the test or resource.""" 46 47
48 - def __init__(self, arguments = None, **args):
49 """Construct a new 'Runnable'. 50 51 'arguments' -- As for 'Extension.__init__'. 52 53 'args' -- As for 'Extension.__init__'.""" 54 55 self.__id = args.pop(self.EXTRA_ID) 56 self.__database = args.pop(self.EXTRA_DATABASE) 57 if arguments: args.update(arguments) 58 super(Suite, self).__init__(**args)
59 60 61
62 - def GetDatabase(self):
63 """Return the 'Database' that contains this suite. 64 65 returns -- The 'Database' that contains this suite.""" 66 67 return self.__database
68 69
70 - def GetId(self):
71 """Return the ID of this test suite.""" 72 73 return self.__id
74 75
76 - def GetTestIds(self):
77 """Return the tests contained in this suite. 78 79 returns -- A sequence of labels corresponding to the tests 80 contained in this suite. Tests that are contained in this suite 81 only because they are contained in a suite which is itself 82 contained in this suite are not returned.""" 83 84 return []
85 86
87 - def GetSuiteIds(self):
88 """Return the suites contained in this suite. 89 90 returns -- A sequence of labels corresponding to the suites 91 contained in this suite. Suites that are contained in this suite 92 only because they are contained in a suite which is itself 93 contained in this suite are not returned.""" 94 95 return []
96 97
98 - def IsImplicit(self):
99 """Return true if this is an implicit test suite. 100 101 Implicit test suites cannot be edited.""" 102 103 raise NotImplementedError
104 105
106 - def GetAllTestAndSuiteIds(self):
107 """Return the tests/suites contained in this suite and its subsuites. 108 109 returns -- A pair '(test_ids, suite_ids)'. The 'test_ids' and 110 'suite_ids' elements are both sequences of labels. The values 111 returned include all tests and suites that are contained in this 112 suite and its subsuites, recursively.""" 113 114 suite = self 115 116 test_ids = [] 117 suite_ids = [] 118 119 # Maintain a work list of suites to process. 120 work_list = [suite] 121 # Process until the work list is empty. 122 while len(work_list) > 0: 123 suite = work_list.pop(0) 124 # Accumulate test and resource IDs in the suite. 125 test_ids.extend(suite.GetTestIds()) 126 # Find sub suites in the suite. 127 sub_suite_ids = suite.GetSuiteIds() 128 # Accumulate them. 129 suite_ids.extend(sub_suite_ids) 130 # Retrieve the 'Suite' objects. 131 sub_suites = map(self.GetDatabase().GetSuite, sub_suite_ids) 132 # Don't expand ordinary suites contained in implicit suites. 133 if suite.IsImplicit(): 134 sub_suites = filter(lambda s: s.IsImplicit(), sub_suites) 135 # Add contained suites to the work list. 136 work_list.extend(sub_suites) 137 138 return test_ids, suite_ids
139