summaryrefslogtreecommitdiff
path: root/systest
blob: 0c35f2a1cb9a5b61d8f8bdd8fd3d4e82e41c5ba4 (plain)
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
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python

import cliapp
import imp
import logging
import os
import re
import subprocess
import unittest

import systest


class SystemTest(cliapp.Application):

    def add_settings(self):
        self.settings.string(['target'], 'target domain name or IP address')
        self.settings.string(['user'], 'user on target')
        self.settings.string(['user-password'], 'password for target user')

    def process_args(self, args):
        loader = unittest.defaultTestLoader
        loader.suiteClass = self.create_suite
        suite = unittest.TestSuite()
        for filename in args:
            module = self.load_module(filename)
            suite.addTest(loader.loadTestsFromModule(module))
        unittest.TextTestRunner().run(suite)

    def create_suite(self, tests):
        for test in tests:
            test.settings = self.settings
        suite = unittest.TestSuite(tests)
        return suite

    def load_module(self, filename):
        for t in imp.get_suffixes():
            suffix, mode, kind = t
            if filename.endswith(suffix):
                module_name = os.path.basename(filename[:-len(suffix)])
                with open(filename, mode) as f:
                    return imp.load_module(module_name, f, filename, t)
        raise Exception("Unknown module: %s" % filename)


if __name__ == '__main__':
    SystemTest().run()