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