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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Interfaces for Trial.
Maintainer: Jonathan Lange
"""
from __future__ import division, absolute_import
import zope.interface as zi
from zope.interface import Attribute
class ITestCase(zi.Interface):
"""
The interface that a test case must implement in order to be used in Trial.
"""
failureException = zi.Attribute(
"The exception class that is raised by failed assertions")
def __call__(result):
"""
Run the test. Should always do exactly the same thing as run().
"""
def countTestCases():
"""
Return the number of tests in this test case. Usually 1.
"""
def id():
"""
Return a unique identifier for the test, usually the fully-qualified
Python name.
"""
def run(result):
"""
Run the test, storing the results in C{result}.
@param result: A L{TestResult}.
"""
def shortDescription():
"""
Return a short description of the test.
"""
class IReporter(zi.Interface):
"""
I report results from a run of a test suite.
"""
stream = zi.Attribute(
"Deprecated in Twisted 8.0. "
"The io-stream that this reporter will write to")
tbformat = zi.Attribute("Either 'default', 'brief', or 'verbose'")
args = zi.Attribute(
"Additional string argument passed from the command line")
shouldStop = zi.Attribute(
"""
A boolean indicating that this reporter would like the test run to stop.
""")
separator = Attribute(
"Deprecated in Twisted 8.0. "
"A value which will occasionally be passed to the L{write} method.")
testsRun = Attribute(
"""
The number of tests that seem to have been run according to this
reporter.
""")
def startTest(method):
"""
Report the beginning of a run of a single test method.
@param method: an object that is adaptable to ITestMethod
"""
def stopTest(method):
"""
Report the status of a single test method
@param method: an object that is adaptable to ITestMethod
"""
def startSuite(name):
"""
Deprecated in Twisted 8.0.
Suites which wish to appear in reporter output should call this
before running their tests.
"""
def endSuite(name):
"""
Deprecated in Twisted 8.0.
Called at the end of a suite, if and only if that suite has called
C{startSuite}.
"""
def cleanupErrors(errs):
"""
Deprecated in Twisted 8.0.
Called when the reactor has been left in a 'dirty' state
@param errs: a list of L{twisted.python.failure.Failure}s
"""
def upDownError(userMeth, warn=True, printStatus=True):
"""
Deprecated in Twisted 8.0.
Called when an error occurs in a setUp* or tearDown* method
@param warn: indicates whether or not the reporter should emit a
warning about the error
@type warn: Boolean
@param printStatus: indicates whether or not the reporter should
print the name of the method and the status
message appropriate for the type of error
@type printStatus: Boolean
"""
def addSuccess(test):
"""
Record that test passed.
"""
def addError(test, error):
"""
Record that a test has raised an unexpected exception.
@param test: The test that has raised an error.
@param error: The error that the test raised. It will either be a
three-tuple in the style of C{sys.exc_info()} or a
L{Failure<twisted.python.failure.Failure>} object.
"""
def addFailure(test, failure):
"""
Record that a test has failed with the given failure.
@param test: The test that has failed.
@param failure: The failure that the test failed with. It will
either be a three-tuple in the style of C{sys.exc_info()}
or a L{Failure<twisted.python.failure.Failure>} object.
"""
def addExpectedFailure(test, failure, todo=None):
"""
Record that the given test failed, and was expected to do so.
In Twisted 15.5 and prior, C{todo} was a mandatory parameter.
@type test: L{unittest.TestCase}
@param test: The test which this is about.
@type error: L{failure.Failure}
@param error: The error which this test failed with.
@type todo: L{unittest.Todo}
@param todo: The reason for the test's TODO status. If L{None}, a
generic reason is used.
"""
def addUnexpectedSuccess(test, todo=None):
"""
Record that the given test failed, and was expected to do so.
In Twisted 15.5 and prior, C{todo} was a mandatory parameter.
@type test: L{unittest.TestCase}
@param test: The test which this is about.
@type todo: L{unittest.Todo}
@param todo: The reason for the test's TODO status. If L{None}, a
generic reason is used.
"""
def addSkip(test, reason):
"""
Record that a test has been skipped for the given reason.
@param test: The test that has been skipped.
@param reason: An object that the test case has specified as the reason
for skipping the test.
"""
def printSummary():
"""
Deprecated in Twisted 8.0, use L{done} instead.
Present a summary of the test results.
"""
def printErrors():
"""
Deprecated in Twisted 8.0, use L{done} instead.
Present the errors that have occurred during the test run. This method
will be called after all tests have been run.
"""
def write(string):
"""
Deprecated in Twisted 8.0, use L{done} instead.
Display a string to the user, without appending a new line.
"""
def writeln(string):
"""
Deprecated in Twisted 8.0, use L{done} instead.
Display a string to the user, appending a new line.
"""
def wasSuccessful():
"""
Return a boolean indicating whether all test results that were reported
to this reporter were successful or not.
"""
def done():
"""
Called when the test run is complete.
This gives the result object an opportunity to display a summary of
information to the user. Once you have called C{done} on an
L{IReporter} object, you should assume that the L{IReporter} object is
no longer usable.
"""
|