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