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

Source Code for Module test_suite.test_suite_runner

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-2012 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  # Dependency checks. 
 23  import dep_check 
 24   
 25  # Python module imports. 
 26  import os 
 27  import sys 
 28  if dep_check.wx_module: 
 29      import wx 
 30   
 31  # Formatting. 
 32  from test_suite.formatting import subtitle, summary_line, title 
 33   
 34  # Import the test suite categories. 
 35  if dep_check.wx_module: 
 36      from test_suite.gui_tests import GUI_test_runner 
 37  from test_suite.system_tests import System_test_runner 
 38  from test_suite.unit_tests.unit_test_runner import Unit_test_runner 
 39   
 40  # relax module imports. 
 41  if dep_check.wx_module: 
 42      from gui import relax_gui 
 43      from gui import interpreter 
 44  from test_suite.relax_test_runner import GuiTestRunner, RelaxTestRunner 
 45  from status import Status; status = Status() 
 46   
 47   
48 -class Test_suite_runner:
49 """Class for running all components of the relax test suite. 50 51 This currently includes the following categories of tests: 52 - System/functional tests. 53 - Unit tests. 54 - GUI tests. 55 """ 56
57 - def __init__(self, tests=[], from_gui=False, categories=['system', 'unit', 'gui']):
58 """Store the list of tests to preform. 59 60 The test list should be something like ['N_state_model.test_stereochem_analysis']. The first part is the imported test case class, the second is the specific test. 61 62 63 @keyword tests: The list of tests to preform. If left at [], then all tests will be run. 64 @type tests: list of str 65 @keyword from_gui: A flag which indicates if the tests are being run from the GUI or not. 66 @type from_gui: bool 67 @keyword categories: The list of test categories to run, for example ['system', 'unit', 'gui'] for all tests. 68 @type categories: list of str 69 """ 70 71 # Store the args. 72 self.tests = tests 73 self.from_gui = from_gui 74 self.categories = categories 75 76 # A list for skipped tests. 77 status.skip = [] 78 79 # Set up the test runner. 80 if from_gui: 81 self.runner = GuiTestRunner(stream=sys.stdout) 82 else: 83 self.runner = RelaxTestRunner(stream=sys.stdout)
84 85
86 - def run_all_tests(self):
87 """Execute all of the test suite test types.""" 88 89 # Execute the system/functional tests. 90 if 'system' in self.categories: 91 self.run_system_tests(summary=False) 92 93 # Execute the unit tests. 94 if 'unit' in self.categories: 95 self.run_unit_tests(summary=False) 96 97 # Execute the GUI tests. 98 if 'gui' in self.categories: 99 self.run_gui_tests(summary=False) 100 101 # Print out a summary of the test suite. 102 self.summary()
103 104
105 - def run_gui_tests(self, summary=True):
106 """Execute the GUI tests. 107 108 @keyword summary: A flag which if True will cause a summary to be printed. 109 @type summary: bool 110 """ 111 112 # Print a header. 113 title('GUI tests') 114 115 # Run the tests. 116 if dep_check.wx_module: 117 # Set up the GUI if needed (i.e. not in GUI mode already). 118 app = wx.GetApp() 119 if app == None: 120 # Initialise. 121 app = wx.App(redirect=False) 122 123 # Build the GUI. 124 app.gui = relax_gui.Main(parent=None, id=-1, title="") 125 126 # Execute the GUI tests. 127 gui_runner = GUI_test_runner() 128 self.gui_result = gui_runner.run(self.tests, runner=self.runner) 129 130 # Clean up for the GUI, if not in GUI mode. 131 if status.test_mode: 132 # Terminate the interpreter thread to allow the tests to cleanly exit. 133 interpreter_thread = interpreter.Interpreter() 134 interpreter_thread.exit() 135 136 # Stop the GUI main loop. 137 app.ExitMainLoop() 138 139 # No wx module installed. 140 else: 141 print("All GUI tests skipped due to the missing/broken wx module.\n") 142 self.gui_result = 'skip' 143 144 # Print out a summary of the test suite. 145 if summary: 146 self.summary()
147 148
149 - def run_system_tests(self, summary=True):
150 """Execute the system/functional tests. 151 152 @keyword summary: A flag which if True will cause a summary to be printed. 153 @type summary: bool 154 """ 155 156 # Print a header. 157 title('System / functional tests') 158 159 # Run the tests. 160 system_runner = System_test_runner() 161 self.system_result = system_runner.run(self.tests, runner=self.runner) 162 163 # Print out a summary of the test suite. 164 if summary: 165 self.summary()
166 167
168 - def run_unit_tests(self, summary=True):
169 """Execute the unit tests. 170 171 @keyword summary: A flag which if True will cause a summary to be printed. 172 @type summary: bool 173 """ 174 175 # Print a header. 176 title('Unit tests') 177 178 # Run the tests. 179 unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests') 180 self.unit_result = unit_runner.run(runner=self.runner) 181 182 # Print out a summary of the test suite. 183 if summary: 184 self.summary()
185 186
187 - def summary(self):
188 """Print out a summary of the relax test suite.""" 189 190 # Title. 191 title("Summary of the relax test suite") 192 193 # The skipped tests. 194 self.summary_skipped() 195 196 # Subtitle. 197 subtitle("Synopsis") 198 199 # System/functional test summary. 200 if hasattr(self, 'system_result'): 201 summary_line("System/functional tests", self.system_result) 202 203 # Unit test summary. 204 if hasattr(self, 'unit_result'): 205 summary_line("Unit tests", self.unit_result) 206 207 # GUI test summary. 208 if hasattr(self, 'gui_result'): 209 summary_line("GUI tests", self.gui_result) 210 211 # Synopsis. 212 if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result'): 213 if self.gui_result == "skip": 214 status = self.system_result and self.unit_result 215 else: 216 status = self.system_result and self.unit_result and self.gui_result 217 summary_line("Synopsis", status) 218 219 # End. 220 print('\n\n')
221 222
223 - def summary_skipped(self):
224 """Print out information about skipped tests.""" 225 226 # Counts. 227 system_count = {} 228 unit_count = {} 229 gui_count = {} 230 for i in range(len(status.skipped_tests)): 231 # Alias. 232 test = status.skipped_tests[i] 233 234 # Initialise in needed. 235 if not test[1] in system_count: 236 system_count[test[1]] = 0 237 unit_count[test[1]] = 0 238 gui_count[test[1]] = 0 239 240 # A system test. 241 if test[2] == 'system': 242 system_count[test[1]] += 1 243 244 # A unit test. 245 if test[2] == 'unit': 246 unit_count[test[1]] += 1 247 248 # A GUI test. 249 if test[2] == 'gui': 250 gui_count[test[1]] += 1 251 252 # The missing modules. 253 missing_modules = sorted(system_count.keys()) 254 subtitle("Optional packages/modules") 255 256 # Nothing missing. 257 if not missing_modules: 258 # Except for the wx module! 259 if not dep_check.wx_module and hasattr(self, 'gui_result'): 260 print("All GUI tests skipped due to the missing wxPython module, no other tests skipped due to missing modules.\n") 261 262 # Normal printout. 263 else: 264 print("No tests skipped due to missing modules.\n") 265 266 # The skip the table. 267 return 268 269 # Header. 270 print("Tests skipped due to missing packages/modules:\n") 271 header = "%-30s" % "Module" 272 if len(system_count): 273 header = "%s %20s" % (header, "System test count") 274 if len(unit_count): 275 header = "%s %20s" % (header, "Unit test count") 276 if len(gui_count): 277 header = "%s %20s" % (header, "GUI test count") 278 print('-'*len(header)) 279 print(header) 280 print('-'*len(header)) 281 282 # The table. 283 for module in missing_modules: 284 text = "%-30s" % module 285 if len(system_count): 286 text = "%s %20s" % (text, system_count[module]) 287 if len(unit_count): 288 text = "%s %20s" % (text, unit_count[module]) 289 if len(gui_count): 290 text = "%s %20s" % (text, gui_count[module]) 291 print(text) 292 293 294 # End the table. 295 print('-'*len(header)) 296 print("\n")
297