Home | Trees | Indices | Help |
---|
|
1 ######################################################################## 2 # 3 # File: parameter_database.py 4 # Author: Stefan Seefeld 5 # Date: 2005-01-17 6 # 7 # Contents: 8 # Test database that parametrizes another test database.. 9 # 10 # Copyright (c) 2005 by CodeSourcery, LLC. All rights reserved. 11 # 12 # For license terms see the file COPYING. 13 # 14 ######################################################################## 15 16 ######################################################################## 17 # imports 18 ######################################################################## 19 20 from qm.test.database import * 21 from qm.test.suite import * 22 23 ######################################################################## 24 # classes 25 ######################################################################## 2628 """A database that parametrizes another database. 'Parameter' in this 29 context refers to any name that is used as a label, and which stands 30 for a specific set of arguments passed to tests. 31 32 The 'ParameterDatabase' class is abstract. Subclasses need to implement 33 the '_GetParametersForTest' as well as the '_GetArgumentsForParameter' 34 method. 35 """ 3635938 """ImplicitSuite represents a suite obtained from a test and a set 39 of parameters applied to it.""" 40 46 4759 6049 50 database = self.GetDatabase() 51 id = self.GetId() 52 return map(lambda p, db = database, id = id: db.JoinLabels(id, p), 53 database._GetParametersForTest(id))54 5562 """As tests from the wrapped Database are mapped to suites, suites 63 from the wrapped Database have to be recreated with all tests 64 replaced by ImplicitSuite instances. Additionally, new (explicit) 65 suites may be added.""" 66117 11868 """Take over suite_ids from the wrapped database but replace 69 test_ids by suite_ids if there are parameters available for 70 them.""" 71 72 Suite.__init__(self, {}, 73 qmtest_id = suite.GetId(), 74 qmtest_database = db) 75 self.__suite = suite 76 self.__suite_ids = suite_ids or []77 7880 81 suite_ids = self.__suite.GetSuiteIds() 82 for t in self.__suite.GetTestIds(): 83 if self.GetDatabase()._GetParametersForTest(t): 84 suite_ids.append(t) 85 return suite_ids + self.__suite_ids86 8789 90 test_ids = [] 91 for t in self.__suite.GetTestIds(): 92 if not self.GetDatabase()._GetParametersForTest(t): 93 test_ids.append(t) 94 return test_ids95 96 100 101103 104 db = self.GetDatabase() 105 orig_test_ids, suite_ids = self.__suite.GetAllTestAndSuiteIds() 106 test_ids = [] 107 for test in orig_test_ids: 108 parameters = db._GetParametersForTest(test) 109 if parameters: 110 suite_ids.append(test) 111 test_ids.extend(map(lambda p, test=test, db=db: 112 db.JoinLabels(test, p), 113 parameters)) 114 else: 115 test_ids.append(test) 116 return test_ids, suite_ids + self.__suite_ids120 """ParameterSuite represents a suite obtained from applying a 121 given parameter to a suite from the wrapped DB.""" 122161 162124 """Construct a ParameterSuite. 125 126 database -- The database this suite refers to. 127 128 suite -- The original suite this suite parametrizes. 129 130 parameter -- The value for the parameter to apply to the suite.""" 131 132 Suite.__init__(self, {}, 133 qmtest_id = database.JoinLabels(suite.GetId(), 134 parameter), 135 qmtest_database = database) 136 self.__suite = suite 137 self.__parameter = parameter138 139141 """ParameterSuites contain ParameterSuites which wrap suites 142 contained in the wrapped suite.""" 143 144 database = self.GetDatabase() 145 return map(lambda id, db = database, p = self.__parameter: 146 db.JoinLabels(id, p), self.__suite.GetSuiteIds())147 148150 """ParameterSuites contain Tests obtained by applying the given 151 parameter set to the tests contained in the wrapped suite.""" 152 153 database = self.GetDatabase() 154 return map(lambda id, db = database, p = self.__parameter: 155 db.JoinLabels(id, p), self.__suite.GetTestIds())156 157164 165 self.label_class = database.label_class 166 Database.__init__(self, path, arguments) 167 self.__db = database168 169 173 174176 """Return a list of parameters that can be applied to the test 177 'test_id'.""" 178 179 return []180 181183 """Return the set of arguments for this parameter. 184 185 'test_id' -- The test id to which the parameter belongs. 186 187 'parameter' -- The parameter for which the arguments are queried. 188 189 returns -- A dictionary containing the argument as name/value pairs.""" 190 191 return {}192 193195 196 directory, basename = self.SplitLabel(test_id) 197 198 if not self.HasTest(test_id): 199 raise NoSuchTestError, test_id 200 201 test = self.__db.GetTest(directory) 202 # now generate a new test 203 arguments = test.GetArguments() 204 205 #override parameters 206 arguments.update(self._GetArgumentsForParameter(directory, basename)) 207 return TestDescriptor(self, test_id, test.GetClassName(), 208 arguments)209211 212 # If test_id is a parametrized test, its basename has to refer to 213 # a parameter set and the directory to a test in the wrapped DB. 214 # 215 # Else basename must not be a parameter set, and test_id a test 216 # in the wrapped DB. 217 218 directory, basename = self.SplitLabel(test_id) 219 220 return (basename in self._GetParametersForTest(directory) 221 and self.__db.HasTest(directory) 222 or self.__db.HasTest(test_id))223 224226 227 # directory may be a test in the wrapped DB... 228 if self.__db.HasTest(directory): 229 ids = [directory] 230 # ...or a directory, in which case we only take it into account 231 # if scan_subdirs == 1. 232 elif scan_subdirs: 233 ids = self.__db.GetTestIds(directory, scan_subdirs) 234 else: 235 return [] 236 237 tests = [] 238 for p in self._GetParametersForTest(directory): 239 tests += map(lambda x, p = p, db = self: db.JoinLabels(x, p), 240 ids) 241 return tests242 243245 246 # If suite_id refers to a suite in the WD, wrap it. 247 if self.__db.HasSuite(suite_id): 248 return ParameterDatabase.WrapperSuite(self, 249 self.__db.GetSuite(suite_id)) 250 251 # If suite_id refers to a test in the WD, parametrize it. 252 elif self.__db.HasTest(suite_id): 253 return ParameterDatabase.ImplicitSuite(self, suite_id) 254 255 raise NoSuchSuiteError, suite_id256 257259 260 directory, basename = self.SplitLabel(suite_id) 261 return (basename in self._GetParametersForTest(directory) 262 and self.__db.HasSuite(directory) 263 or self.__db.HasSuite(suite_id) 264 or self.__db.HasTest(suite_id))265 266268 269 if self.__db.HasTest(directory): 270 return [] 271 272 suite_ids = self.__db.GetSuiteIds(directory, scan_subdirs) 273 test_ids = self.__db.GetTestIds(directory, scan_subdirs) 274 param_ids = map(lambda p, d = directory, db = self: 275 db.JoinLabels(d, p), 276 self._GetParametersForTest(directory)) 277 278 # The set of all (non-recursive) suite ids is composed of the 279 # original suite ids plus original test ids (now being suite ids) 280 # as well as explicit suites obtained by combining the given 281 # directory with all parameters. 282 ids = suite_ids + test_ids + param_ids 283 if not scan_subdirs: 284 return ids 285 else: 286 # The set of all suite ids is composed of the set above plus 287 # everything above combined with all parameters. 288 expl_ids = [] 289 for p in self._GetParametersForTest(directory): 290 expl_ids += map(lambda x, p = p, db = self: 291 db.JoinLabels(x, p), suite_ids + test_ids) 292 return ids + expl_ids293 294 298 299 303 304306 307 if self.__db.HasTest(directory): 308 return [] 309 310 return self.__db.GetResourceIds(directory, scan_subdirs)311 312314 315 if kind == Database.TEST: 316 return self.GetTestIds(directory, scan_subdirs) 317 elif kind == Database.RESOURCE: 318 return self.GetResourceIds(directory, scan_subdirs) 319 else: 320 return self.__db.GetIds(kind, directory, scan_subdirs)321 322324 325 # GetSubdirectories returns the subdirectories of the given directory. 326 # As this Database turns all tests from the wrapped Database into 327 # ImplicitSuites, we have to account for them here. 328 # 329 # Further, while 'directory' has to be a directory when looked at it 330 # from this Database, it may well be a test in the context of the wrapped 331 # Database, in which case it can't have subdirectories. 332 if self.__db.HasTest(directory): 333 return [] 334 335 subdirs = self.__db.GetSubdirectories(directory) 336 subdirs += [d[directory and len(directory) + 1 or 0:] # Remove common prefix. 337 for d in self.__db.GetTestIds(directory, False)] 338 return subdirs339 340 344 345 349 350 354 355
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Dec 23 12:30:46 2011 | http://epydoc.sourceforge.net |