/usr/lib/python3/dist-packages/testtools/testresult/doubles.py is in python3-testtools 1.8.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | # Copyright (c) 2009-2015 testtools developers. See LICENSE for details.
"""Doubles of test result objects, useful for testing unittest code."""
__all__ = [
'Python26TestResult',
'Python27TestResult',
'ExtendedTestResult',
'StreamResult',
]
from testtools.tags import TagContext
class LoggingBase(object):
"""Basic support for logging of results."""
def __init__(self, event_log=None):
if event_log is None:
event_log = []
self._events = event_log
self.shouldStop = False
self._was_successful = True
self.testsRun = 0
class Python26TestResult(LoggingBase):
"""A precisely python 2.6 like test result, that logs."""
def addError(self, test, err):
self._was_successful = False
self._events.append(('addError', test, err))
def addFailure(self, test, err):
self._was_successful = False
self._events.append(('addFailure', test, err))
def addSuccess(self, test):
self._events.append(('addSuccess', test))
def startTest(self, test):
self._events.append(('startTest', test))
self.testsRun += 1
def stop(self):
self.shouldStop = True
def stopTest(self, test):
self._events.append(('stopTest', test))
def wasSuccessful(self):
return self._was_successful
class Python27TestResult(Python26TestResult):
"""A precisely python 2.7 like test result, that logs."""
def __init__(self, event_log=None):
super(Python27TestResult, self).__init__(event_log)
self.failfast = False
def addError(self, test, err):
super(Python27TestResult, self).addError(test, err)
if self.failfast:
self.stop()
def addFailure(self, test, err):
super(Python27TestResult, self).addFailure(test, err)
if self.failfast:
self.stop()
def addExpectedFailure(self, test, err):
self._events.append(('addExpectedFailure', test, err))
def addSkip(self, test, reason):
self._events.append(('addSkip', test, reason))
def addUnexpectedSuccess(self, test):
self._events.append(('addUnexpectedSuccess', test))
if self.failfast:
self.stop()
def startTestRun(self):
self._events.append(('startTestRun',))
def stopTestRun(self):
self._events.append(('stopTestRun',))
class ExtendedTestResult(Python27TestResult):
"""A test result like the proposed extended unittest result API."""
def __init__(self, event_log=None):
super(ExtendedTestResult, self).__init__(event_log)
self._tags = TagContext()
def addError(self, test, err=None, details=None):
self._was_successful = False
self._events.append(('addError', test, err or details))
def addFailure(self, test, err=None, details=None):
self._was_successful = False
self._events.append(('addFailure', test, err or details))
def addExpectedFailure(self, test, err=None, details=None):
self._events.append(('addExpectedFailure', test, err or details))
def addSkip(self, test, reason=None, details=None):
self._events.append(('addSkip', test, reason or details))
def addSuccess(self, test, details=None):
if details:
self._events.append(('addSuccess', test, details))
else:
self._events.append(('addSuccess', test))
def addUnexpectedSuccess(self, test, details=None):
self._was_successful = False
if details is not None:
self._events.append(('addUnexpectedSuccess', test, details))
else:
self._events.append(('addUnexpectedSuccess', test))
def progress(self, offset, whence):
self._events.append(('progress', offset, whence))
def startTestRun(self):
super(ExtendedTestResult, self).startTestRun()
self._was_successful = True
self._tags = TagContext()
def startTest(self, test):
super(ExtendedTestResult, self).startTest(test)
self._tags = TagContext(self._tags)
def stopTest(self, test):
self._tags = self._tags.parent
super(ExtendedTestResult, self).stopTest(test)
@property
def current_tags(self):
return self._tags.get_current_tags()
def tags(self, new_tags, gone_tags):
self._tags.change_tags(new_tags, gone_tags)
self._events.append(('tags', new_tags, gone_tags))
def time(self, time):
self._events.append(('time', time))
def wasSuccessful(self):
return self._was_successful
class StreamResult(object):
"""A StreamResult implementation for testing.
All events are logged to _events.
"""
def __init__(self, event_log=None):
if event_log is None:
event_log = []
self._events = event_log
def startTestRun(self):
self._events.append(('startTestRun',))
def stopTestRun(self):
self._events.append(('stopTestRun',))
def status(self, test_id=None, test_status=None, test_tags=None,
runnable=True, file_name=None, file_bytes=None, eof=False,
mime_type=None, route_code=None, timestamp=None):
self._events.append(
('status', test_id, test_status, test_tags,
runnable, file_name, file_bytes, eof, mime_type, route_code,
timestamp))
|