1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import dep_check
24 import sys
25 from time import time
26 from unittest import TextTestRunner
27 if dep_check.wx_module:
28 import wx
29
30
31 from compat import StringIO
32 from compat import TextTestResult
33 from status import Status; status = Status()
34
35
37 """A replacement for the TextTestResult class.
38
39 This class is designed to catch STDOUT and STDERR during the execution of each test and to
40 prepend the output to the failure and error reports normally generated by TextTestRunner.
41 """
42
43 - def __init__(self, stream, descriptions, verbosity, timing=False):
44 """Initialise the RelaxTestResult object with relax specific variables.
45
46 @keyword timing: A flag which if True will enable timing of individual tests.
47 @type timing: bool
48 """
49
50
51 super(RelaxTestResult, self).__init__(stream, descriptions, verbosity)
52
53
54 self.timing_flag = timing
55
56
58 """Override of the TestResult.addError() method.
59
60 The STDOUT and STDERR captured text is prepended to the error text here.
61
62
63 @param test: The test object.
64 @type test: TestCase instance
65 @param err: A tuple of values as returned by sys.exc_info().
66 @type err: tuple of values
67 """
68
69
70 super(RelaxTestResult, self).addError(test, err)
71
72
73 self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + self.errors[-1][1])
74
75
76 if self.timing_flag:
77 self.write_time(test.id())
78
79
81 """Override of the TestResult.addFailure() method.
82
83 The STDOUT and STDERR captured text is prepended to the failure text here.
84
85
86 @param test: The test object.
87 @type test: TestCase instance
88 @param err: A tuple of values as returned by sys.exc_info().
89 @type err: tuple of values
90 """
91
92
93 super(RelaxTestResult, self).addFailure(test, err)
94
95
96 self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + self.failures[-1][1])
97
98
99 if self.timing_flag:
100 self.write_time(test.id())
101
102
104 """The method for a successful test.
105
106 @param test: The test object.
107 @type test: TestCase instance
108 """
109
110
111 super(RelaxTestResult, self).addSuccess(test)
112
113
114 if self.timing_flag:
115 self.write_time(test.id())
116
117
119 """Override of the TextTestResult.startTest() method.
120
121 The start of STDOUT and STDERR capture occurs here.
122 """
123
124
125 self.orig_stdout = sys.stdout
126 self.orig_stderr = sys.stderr
127
128
129 self.capt = StringIO()
130 if not status.debug:
131 sys.stdout = self.capt
132 sys.stderr = self.capt
133
134
135 status.exec_lock.test_name = str(test)
136
137
138 if self.timing_flag:
139 self.time = time()
140
141
142 super(RelaxTestResult, self).startTest(test)
143
144
146 """Override of the TextTestResult.stopTest() method.
147
148 The end of STDOUT and STDERR capture occurs here.
149 """
150
151
152 sys.stdout = self.orig_stdout
153 sys.stderr = self.orig_stderr
154
155
157 """Write the timing of the test to the stream.
158
159 @param test_name: The TestCase name.
160 @type test_name: str
161 """
162
163
164 self.time -= time()
165
166
167 test_name = test_name.split('.')
168 test_name = "%s.%s" % (test_name[-2], test_name[-1])
169
170
171 self.stream.write(' %7.2f s for %s.\n' % (-self.time, test_name))
172
173
174
176 """A replacement for the TextTestResult class for the GUI."""
177
179 """Override of the RelaxTestResult.stopTest() method.
180
181 The end of STDOUT and STDERR capture occurs here.
182 """
183
184
185 super(GuiTestResult, self).stopTest(test)
186
187
188 wx.GetApp().Yield(True)
189
190
191
193 """A replacement unittest runner.
194
195 This runner is designed to catch STDOUT during the execution of each test and to prepend the
196 output to the failure and error reports normally generated by TextTestRunner.
197 """
198
199 - def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None, timing=False):
200 """Initialise the class, storing the timing flag.
201
202 @keyword timing: A flag which if True will enable timing of individual tests.
203 @type timing: bool
204 """
205
206
207 if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.version_info[0] == 2 and sys.version_info[1] <= 6):
208 super(RelaxTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity)
209 else:
210 super(RelaxTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=resultclass)
211
212
213 self.timing_flag = timing
214
215
217 """Override of the TextTestRunner._makeResult() method."""
218
219 return RelaxTestResult(self.stream, self.descriptions, self.verbosity, timing=self.timing_flag)
220
221
222
224 """A replacement unittest runner.
225
226 This runner is designed to catch STDOUT during the execution of each test and to prepend the
227 output to the failure and error reports normally generated by TextTestRunner.
228 """
229
230 - def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None, timing=False):
231 """Initialise the class, storing the timing flag.
232
233 @keyword timing: A flag which if True will enable timing of individual tests.
234 @type timing: bool
235 """
236
237
238 if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.version_info[0] == 2 and sys.version_info[1] <= 6):
239 super(GuiTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity)
240 else:
241 super(GuiTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=resultclass)
242
243
244 self.timing_flag = timing
245
246
248 """Override of the TextTestRunner._makeResult() method."""
249
250 return GuiTestResult(self.stream, self.descriptions, self.verbosity, timing=self.timing_flag)
251