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 try:
25 from cStringIO import StringIO
26 except ImportError:
27 from io import StringIO
28 import sys
29 try:
30 from unittest import TextTestResult
31 except ImportError:
32 from unittest import _TextTestResult as TextTestResult
33 from unittest import TextTestRunner
34 if dep_check.wx_module:
35 import wx
36
37
38 from status import Status; status = Status()
39
40
42 """A replacement for the TextTestResult class.
43
44 This class is designed to catch STDOUT and STDERR during the execution of each test and to
45 prepend the output to the failure and error reports normally generated by TextTestRunner.
46 """
47
49 """Override of the TextTestResult.startTest() method.
50
51 The start of STDOUT and STDERR capture occurs here.
52 """
53
54
55 self.orig_stdout = sys.stdout
56 self.orig_stderr = sys.stderr
57
58
59 self.capt = StringIO()
60 if not status.debug:
61 sys.stdout = self.capt
62 sys.stderr = self.capt
63
64
65 status.exec_lock.test_name = str(test)
66
67
68 TextTestResult.startTest(self, test)
69
70
72 """Override of the TextTestResult.stopTest() method.
73
74 The end of STDOUT and STDERR capture occurs here.
75 """
76
77
78 sys.stdout = self.orig_stdout
79 sys.stderr = self.orig_stderr
80
81
83 """Override of the TestResult.addError() method.
84
85 The STDOUT and STDERR captured text is prepended to the error text here.
86 """
87
88
89 TextTestResult.addError(self, test, err)
90
91
92 self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + self.errors[-1][1])
93
94
96 """Override of the TestResult.addFailure() method.
97
98 The STDOUT and STDERR captured text is prepended to the failure text here.
99 """
100
101
102 TextTestResult.addFailure(self, test, err)
103
104
105 self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + self.failures[-1][1])
106
107
108
110 """A replacement for the TextTestResult class for the GUI."""
111
113 """Override of the RelaxTestResult.stopTest() method.
114
115 The end of STDOUT and STDERR capture occurs here.
116 """
117
118
119 super(GuiTestResult, self).stopTest(test)
120
121
122 wx.GetApp().Yield(True)
123
124
125
127 """A replacement unittest runner.
128
129 This runner is designed to catch STDOUT during the execution of each test and to prepend the
130 output to the failure and error reports normally generated by TextTestRunner.
131 """
132
134 """Override of the TextTestRunner._makeResult() method."""
135
136 return RelaxTestResult(self.stream, self.descriptions, self.verbosity)
137
138
139
141 """A replacement unittest runner.
142
143 This runner is designed to catch STDOUT during the execution of each test and to prepend the
144 output to the failure and error reports normally generated by TextTestRunner.
145 """
146
148 """Override of the TextTestRunner._makeResult() method."""
149
150 return GuiTestResult(self.stream, self.descriptions, self.verbosity)
151