Package openid :: Package test :: Module datadriven
[frames] | no frames]

Source Code for Module openid.test.datadriven

 1  import unittest 
 2  import types 
 3   
4 -class DataDrivenTestCase(unittest.TestCase):
5 cases = [] 6
7 - def generateCases(cls):
8 return cls.cases
9 10 generateCases = classmethod(generateCases) 11
12 - def loadTests(cls):
13 tests = [] 14 for case in cls.generateCases(): 15 if isinstance(case, tuple): 16 test = cls(*case) 17 elif isinstance(case, dict): 18 test = cls(**case) 19 else: 20 test = cls(case) 21 tests.append(test) 22 return tests
23 24 loadTests = classmethod(loadTests) 25
26 - def __init__(self, description):
27 unittest.TestCase.__init__(self, 'runOneTest') 28 self.description = description
29
30 - def shortDescription(self):
31 return '%s for %s' % (self.__class__.__name__, self.description)
32
33 -def loadTests(module_name):
34 loader = unittest.defaultTestLoader 35 this_module = __import__(module_name, {}, {}, [None]) 36 37 tests = [] 38 for name in dir(this_module): 39 obj = getattr(this_module, name) 40 if (isinstance(obj, (type, types.ClassType)) and 41 issubclass(obj, unittest.TestCase)): 42 if hasattr(obj, 'loadTests'): 43 tests.extend(obj.loadTests()) 44 else: 45 tests.append(loader.loadTestsFromTestCase(obj)) 46 47 return unittest.TestSuite(tests)
48