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