1import os
2
3# Test results.
4
5class TestResult:
6    def __init__(self, name, isFailure):
7        self.name = name
8        self.isFailure = isFailure
9
10PASS        = TestResult('PASS', False)
11XFAIL       = TestResult('XFAIL', False)
12FAIL        = TestResult('FAIL', True)
13XPASS       = TestResult('XPASS', True)
14UNRESOLVED  = TestResult('UNRESOLVED', True)
15UNSUPPORTED = TestResult('UNSUPPORTED', False)
16
17# Test classes.
18
19class TestFormat:
20    """TestFormat - Test information provider."""
21
22    def __init__(self, name):
23        self.name = name
24
25class TestSuite:
26    """TestSuite - Information on a group of tests.
27
28    A test suite groups together a set of logically related tests.
29    """
30
31    def __init__(self, name, source_root, exec_root, config):
32        self.name = name
33        self.source_root = source_root
34        self.exec_root = exec_root
35        # The test suite configuration.
36        self.config = config
37
38    def getSourcePath(self, components):
39        return os.path.join(self.source_root, *components)
40
41    def getExecPath(self, components):
42        return os.path.join(self.exec_root, *components)
43
44class Test:
45    """Test - Information on a single test instance."""
46
47    def __init__(self, suite, path_in_suite, config):
48        self.suite = suite
49        self.path_in_suite = path_in_suite
50        self.config = config
51        # The test result code, once complete.
52        self.result = None
53        # Any additional output from the test, once complete.
54        self.output = None
55        # The wall time to execute this test, if timing and once complete.
56        self.elapsed = None
57        # The repeat index of this test, or None.
58        self.index = None
59
60    def copyWithIndex(self, index):
61        import copy
62        res = copy.copy(self)
63        res.index = index
64        return res
65
66    def setResult(self, result, output, elapsed):
67        assert self.result is None, "Test result already set!"
68        self.result = result
69        self.output = output
70        self.elapsed = elapsed
71
72    def getFullName(self):
73        return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite)
74
75    def getSourcePath(self):
76        return self.suite.getSourcePath(self.path_in_suite)
77
78    def getExecPath(self):
79        return self.suite.getExecPath(self.path_in_suite)
80