s4-python: Install external included packages only if they're not present on the...
[nivanova/samba-autobuild/.git] / lib / testtools / tests / helpers.py
1 # Copyright (c) 2008 Jonathan M. Lange. See LICENSE for details.
2
3 """Helpers for tests."""
4
5 import sys
6
7 __metaclass__ = type
8 __all__ = [
9     'LoggingResult',
10     ]
11
12 from testtools import TestResult
13
14
15 try:
16     raise Exception
17 except Exception:
18     an_exc_info = sys.exc_info()
19
20 # Deprecated: This classes attributes are somewhat non deterministic which
21 # leads to hard to predict tests (because Python upstream are changing things.
22 class LoggingResult(TestResult):
23     """TestResult that logs its event to a list."""
24
25     def __init__(self, log):
26         self._events = log
27         super(LoggingResult, self).__init__()
28
29     def startTest(self, test):
30         self._events.append(('startTest', test))
31         super(LoggingResult, self).startTest(test)
32
33     def stopTest(self, test):
34         self._events.append(('stopTest', test))
35         super(LoggingResult, self).stopTest(test)
36
37     def addFailure(self, test, error):
38         self._events.append(('addFailure', test, error))
39         super(LoggingResult, self).addFailure(test, error)
40
41     def addError(self, test, error):
42         self._events.append(('addError', test, error))
43         super(LoggingResult, self).addError(test, error)
44
45     def addSkip(self, test, reason):
46         self._events.append(('addSkip', test, reason))
47         super(LoggingResult, self).addSkip(test, reason)
48
49     def addSuccess(self, test):
50         self._events.append(('addSuccess', test))
51         super(LoggingResult, self).addSuccess(test)
52
53     def startTestRun(self):
54         self._events.append('startTestRun')
55         super(LoggingResult, self).startTestRun()
56
57     def stopTestRun(self):
58         self._events.append('stopTestRun')
59         super(LoggingResult, self).stopTestRun()
60
61     def done(self):
62         self._events.append('done')
63         super(LoggingResult, self).done()
64
65 # Note, the following three classes are different to LoggingResult by
66 # being fully defined exact matches rather than supersets.
67 from testtools.testresult.doubles import *