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 self.stream.write(' %7.2f s for %s.\n' % (-self.time, test_name))
168
169
170
172 """A replacement for the TextTestResult class for the GUI."""
173
175 """Override of the RelaxTestResult.stopTest() method.
176
177 The end of STDOUT and STDERR capture occurs here.
178 """
179
180
181 super(GuiTestResult, self).stopTest(test)
182
183
184 wx.GetApp().Yield(True)
185
186
187
189 """A replacement unittest runner.
190
191 This runner is designed to catch STDOUT during the execution of each test and to prepend the
192 output to the failure and error reports normally generated by TextTestRunner.
193 """
194
195 - def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None, timing=False):
196 """Initialise the class, storing the timing flag.
197
198 @keyword timing: A flag which if True will enable timing of individual tests.
199 @type timing: bool
200 """
201
202
203 if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.version_info[0] == 2 and sys.version_info[1] <= 6):
204 super(RelaxTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity)
205 else:
206 super(RelaxTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=resultclass)
207
208
209 self.timing_flag = timing
210
211
213 """Override of the TextTestRunner._makeResult() method."""
214
215 return RelaxTestResult(self.stream, self.descriptions, self.verbosity, timing=self.timing_flag)
216
217
218
220 """A replacement unittest runner.
221
222 This runner is designed to catch STDOUT during the execution of each test and to prepend the
223 output to the failure and error reports normally generated by TextTestRunner.
224 """
225
226 - def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None, timing=False):
227 """Initialise the class, storing the timing flag.
228
229 @keyword timing: A flag which if True will enable timing of individual tests.
230 @type timing: bool
231 """
232
233
234 if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.version_info[0] == 2 and sys.version_info[1] <= 6):
235 super(GuiTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity)
236 else:
237 super(GuiTestRunner, self).__init__(stream=stream, descriptions=descriptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=resultclass)
238
239
240 self.timing_flag = timing
241
242
244 """Override of the TextTestRunner._makeResult() method."""
245
246 return GuiTestResult(self.stream, self.descriptions, self.verbosity, timing=self.timing_flag)
247