File: datadriven.py

package info (click to toggle)
python3-openid 3.0.2%2Bgit20140828-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,672 kB
  • ctags: 2,679
  • sloc: python: 17,137; xml: 234; sh: 15; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import unittest


class DataDrivenTestCase(unittest.TestCase):
    cases = []

    @classmethod
    def generateCases(cls):
        return cls.cases

    @classmethod
    def loadTests(cls):
        tests = []
        for case in cls.generateCases():
            if isinstance(case, tuple):
                test = cls(*case)
            elif isinstance(case, dict):
                test = cls(**case)
            else:
                test = cls(case)
            tests.append(test)
        return tests

    def __init__(self, description):
        super(DataDrivenTestCase, self).__init__(self, 'runOneTest')
        self.description = description

    def shortDescription(self):
        return '%s for %s' % (self.__class__.__name__, self.description)


def loadTests(module_name):
    loader = unittest.defaultTestLoader
    tests = loader.loadTestsFromName(module_name)
    if not tests:
        raise AssertionError("No tests for {0}".format(module_name))
    return unittest.TestSuite(tests)