Package test_suite :: Module relax_test_runner
[hide private]
[frames] | no frames]

Source Code for Module test_suite.relax_test_runner

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  import dep_check 
 24  import sys 
 25  from unittest import TextTestRunner 
 26  if dep_check.wx_module: 
 27      import wx 
 28   
 29  # relax module imports. 
 30  from compat import StringIO 
 31  from compat import TextTestResult 
 32  from status import Status; status = Status() 
 33   
 34   
35 -class RelaxTestResult(TextTestResult):
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
42 - def startTest(self, test):
43 """Override of the TextTestResult.startTest() method. 44 45 The start of STDOUT and STDERR capture occurs here. 46 """ 47 48 # Store the original STDOUT and STDERR for restoring later on. 49 self.orig_stdout = sys.stdout 50 self.orig_stderr = sys.stderr 51 52 # Catch stdout and stderr. 53 self.capt = StringIO() 54 if not status.debug: 55 sys.stdout = self.capt 56 sys.stderr = self.capt 57 58 # Place the test name in the status object. 59 status.exec_lock.test_name = str(test) 60 61 # Execute the normal startTest method. 62 TextTestResult.startTest(self, test)
63 64
65 - def stopTest(self, test):
66 """Override of the TextTestResult.stopTest() method. 67 68 The end of STDOUT and STDERR capture occurs here. 69 """ 70 71 # Restore the IO streams. 72 sys.stdout = self.orig_stdout 73 sys.stderr = self.orig_stderr
74 75
76 - def addError(self, test, err):
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 # Execute the normal addError method. 83 TextTestResult.addError(self, test, err) 84 85 # Prepend the STDOUT and STDERR messages to the second element of the tuple. 86 self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + self.errors[-1][1])
87 88
89 - def addFailure(self, test, err):
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 # Execute the normal addFailure method. 96 TextTestResult.addFailure(self, test, err) 97 98 # Prepend the STDOUT and STDERR messages to the second element of the tuple. 99 self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + self.failures[-1][1])
100 101 102
103 -class GuiTestResult(RelaxTestResult):
104 """A replacement for the TextTestResult class for the GUI.""" 105
106 - def stopTest(self, test):
107 """Override of the RelaxTestResult.stopTest() method. 108 109 The end of STDOUT and STDERR capture occurs here. 110 """ 111 112 # Execute the RelaxTestResult.stopTest() method. 113 super(GuiTestResult, self).stopTest(test) 114 115 # Yield to allow the GUI to be updated. 116 wx.GetApp().Yield(True)
117 118 119
120 -class RelaxTestRunner(TextTestRunner):
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
127 - def _makeResult(self):
128 """Override of the TextTestRunner._makeResult() method.""" 129 130 return RelaxTestResult(self.stream, self.descriptions, self.verbosity)
131 132 133
134 -class GuiTestRunner(TextTestRunner):
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
141 - def _makeResult(self):
142 """Override of the TextTestRunner._makeResult() method.""" 143 144 return GuiTestResult(self.stream, self.descriptions, self.verbosity)
145