~james-w/udd/trunk

201 by James Westby
Add the start of some tests.
1
#!/usr/bin/python
2
3
import sys
4
import unittest
5
419.1.5 by Vincent Ladeuil
Spin off mass-import tests.
6
419.1.2 by Vincent Ladeuil
Start splitting tests into their own modules.
7
class TestLoader(unittest.TestLoader):
8
    """Custom TestLoader to extend the stock python one."""
9
10
    suiteClass = unittest.TestSuite
11
12
    def loadTestsFromModuleNames(self, names):
13
        result = self.suiteClass()
14
        for name in names:
15
            result.addTests(self.loadTestsFromModuleName(name))
16
        return result
17
18
    def loadTestsFromModuleName(self, name):
19
        result = self.suiteClass()
20
        __import__(name, globals(), locals(), [])
21
        module = sys.modules[name]
22
23
        result.addTests(self.loadTestsFromModule(module))
24
        return result
25
26
27
class TestProgram(unittest.TestProgram):
28
29
    def __init__(self, module='__main__'):
30
        # Tell unittest to call createTests
31
        unittest.TestProgram.__init__(self, module, testLoader=TestLoader(),
32
                                      # Tell unittest to call createTests
33
                                      defaultTest=True,
34
                                      )
35
36
    def createTests(self):
37
        suite = self.testLoader.suiteClass()
38
39
        std_tests = self.testLoader.loadTestsFromModule(self.module)
40
        suite.addTests(std_tests)
462.2.1 by Max Bowsher
Create an 'udd' namespace Python module, and move the tests there.
41
        suite.addTests(self.testLoader.loadTestsFromModuleNames([
552.4.3 by Vincent Ladeuil
Add some tests for categorise_failures and fix the eager creation of the config stack (this should be delayed so the test can override iconfig._root_dir first).
42
                    'udd.tests.test_categorise_failures',
43
                    'udd.tests.test_circuit_breaker',
538.3.6 by Jonathan Lange
Add a wrapper Publication object
44
                    'udd.tests.test_commit_database',
552.4.3 by Vincent Ladeuil
Add some tests for categorise_failures and fix the eager creation of the config stack (this should be delayed so the test can override iconfig._root_dir first).
45
                    'udd.tests.test_config',
552.4.4 by Vincent Ladeuil
Restore some sanity in import_package.py function names (main is now the
46
                    'udd.tests.test_count_outstanding_jobs',
47
                    'udd.tests.test_email_failures',
48
                    'udd.tests.test_graph_failures',
538.3.12 by Jonathan Lange
Add a test factory
49
                    'udd.tests.test_helpers',
597.2.1 by James Westby
Re-instate reverted storm code.
50
                    'udd.tests.test_history_database',
552.4.3 by Vincent Ladeuil
Add some tests for categorise_failures and fix the eager creation of the config stack (this should be delayed so the test can override iconfig._root_dir first).
51
                    'udd.tests.test_icommon',
597.2.1 by James Westby
Re-instate reverted storm code.
52
                    'udd.tests.test_idb',
552.4.3 by Vincent Ladeuil
Add some tests for categorise_failures and fix the eager creation of the config stack (this should be delayed so the test can override iconfig._root_dir first).
53
                    'udd.tests.test_import_list',
54
                    'udd.tests.test_import_package',
552.4.7 by Vincent Ladeuil
Fix some more config references adding more tests.
55
                    'udd.tests.test_list_packages',
56
                    'udd.tests.test_logrotate',
538.3.6 by Jonathan Lange
Add a wrapper Publication object
57
                    'udd.tests.test_lpapi',
552.4.3 by Vincent Ladeuil
Add some tests for categorise_failures and fix the eager creation of the config stack (this should be delayed so the test can override iconfig._root_dir first).
58
                    'udd.tests.test_package_database',
59
                    'udd.tests.test_package_to_import',
555.1.1 by Vincent Ladeuil
{pi.import_command} replaces {pi.import_script} and can now embed additional parameters for the import command.
60
                    'udd.tests.test_mass_import',
552.4.3 by Vincent Ladeuil
Add some tests for categorise_failures and fix the eager creation of the config stack (this should be delayed so the test can override iconfig._root_dir first).
61
                    'udd.tests.test_revid_database',
62
                    'udd.tests.test_status_database',
63
                    'udd.tests.test_threads',
64
                    ]))
419.1.2 by Vincent Ladeuil
Start splitting tests into their own modules.
65
        self.test = suite
66
67
201 by James Westby
Add the start of some tests.
68
if __name__ == '__main__':
419.1.2 by Vincent Ladeuil
Start splitting tests into their own modules.
69
    TestProgram(module=__name__)