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