Daniel Dunbar | be7ada7 | 2009-09-08 05:31:18 +0000 | [diff] [blame] | 1 | import os |
| 2 | |
| 3 | # Test results. |
| 4 | |
| 5 | class TestResult: |
| 6 | def __init__(self, name, isFailure): |
| 7 | self.name = name |
| 8 | self.isFailure = isFailure |
| 9 | |
| 10 | PASS = TestResult('PASS', False) |
| 11 | XFAIL = TestResult('XFAIL', False) |
| 12 | FAIL = TestResult('FAIL', True) |
| 13 | XPASS = TestResult('XPASS', True) |
| 14 | UNRESOLVED = TestResult('UNRESOLVED', True) |
| 15 | UNSUPPORTED = TestResult('UNSUPPORTED', False) |
| 16 | |
| 17 | # Test classes. |
| 18 | |
| 19 | class TestFormat: |
| 20 | """TestFormat - Test information provider.""" |
| 21 | |
| 22 | def __init__(self, name): |
| 23 | self.name = name |
| 24 | |
| 25 | class 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 | |
| 44 | class 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 | |
| 58 | def setResult(self, result, output, elapsed): |
| 59 | assert self.result is None, "Test result already set!" |
| 60 | self.result = result |
| 61 | self.output = output |
| 62 | self.elapsed = elapsed |
| 63 | |
| 64 | def getFullName(self): |
| 65 | return self.suite.config.name + '::' + '/'.join(self.path_in_suite) |
| 66 | |
| 67 | def getSourcePath(self): |
| 68 | return self.suite.getSourcePath(self.path_in_suite) |
| 69 | |
| 70 | def getExecPath(self): |
| 71 | return self.suite.getExecPath(self.path_in_suite) |