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-2011 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  import os 
 25  import sys 
 26   
 27  # Dependency checks. 
 28  import dep_check 
 29   
 30  # Formatting. 
 31  from formatting import subtitle, summary_line, title 
 32   
 33  # Import the test suite categories. 
 34  if dep_check.wx_module: 
 35      from gui_tests import GUI_test_runner 
 36  from system_tests import System_test_runner 
 37  from unit_tests.unit_test_runner import Unit_test_runner 
 38   
 39  # relax module imports. 
 40  from relax_test_runner import GuiTestRunner, RelaxTestRunner 
 41  from status import Status; status = Status() 
 42   
 43   
44 -class Test_suite_runner:
45 """Class for running all components of the relax test suite. 46 47 This currently includes the following categories of tests: 48 - System/functional tests. 49 - Unit tests. 50 - GUI tests. 51 """ 52
53 - def __init__(self, tests=[], from_gui=False, categories=['system', 'unit', 'gui']):
54 """Store the list of tests to preform. 55 56 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. 57 58 59 @keyword tests: The list of tests to preform. If left at [], then all tests will be run. 60 @type tests: list of str 61 @keyword from_gui: A flag which indicates if the tests are being run from the GUI or not. 62 @type from_gui: bool 63 @keyword categories: The list of test categories to run, for example ['system', 'unit', 'gui'] for all tests. 64 @type categories: list of str 65 """ 66 67 # Store the args. 68 self.tests = tests 69 self.from_gui = from_gui 70 self.categories = categories 71 72 # A list for skipped tests. 73 status.skip = [] 74 75 # Set up the test runner. 76 if from_gui: 77 self.runner = GuiTestRunner(stream=sys.stdout) 78 else: 79 self.runner = RelaxTestRunner(stream=sys.stdout)
80 81
82 - def run_all_tests(self):
83 """Execute all of the test suite test types.""" 84 85 # Execute the system/functional tests. 86 if 'system' in self.categories: 87 self.run_system_tests(summary=False) 88 89 # Execute the unit tests. 90 if 'unit' in self.categories: 91 self.run_unit_tests(summary=False) 92 93 # Execute the GUI tests. 94 if 'gui' in self.categories: 95 self.run_gui_tests(summary=False) 96 97 # Print out a summary of the test suite. 98 self.summary()
99 100
101 - def run_gui_tests(self, summary=True):
102 """Execute the GUI tests. 103 104 @keyword summary: A flag which if True will cause a summary to be printed. 105 @type summary: bool 106 """ 107 108 # Print a header. 109 title('GUI tests') 110 111 # Run the tests. 112 if dep_check.wx_module: 113 gui_runner = GUI_test_runner() 114 self.gui_result = gui_runner.run(self.tests, runner=self.runner) 115 116 # No wx module installed. 117 else: 118 print("All GUI tests skipped due to the missing/broken wx module.\n") 119 self.gui_result = 'skip' 120 121 # Print out a summary of the test suite. 122 if summary: 123 self.summary()
124 125
126 - def run_system_tests(self, summary=True):
127 """Execute the system/functional tests. 128 129 @keyword summary: A flag which if True will cause a summary to be printed. 130 @type summary: bool 131 """ 132 133 # Print a header. 134 title('System / functional tests') 135 136 # Run the tests. 137 system_runner = System_test_runner() 138 self.system_result = system_runner.run(self.tests, runner=self.runner) 139 140 # Print out a summary of the test suite. 141 if summary: 142 self.summary()
143 144
145 - def run_unit_tests(self, summary=True):
146 """Execute the unit tests. 147 148 @keyword summary: A flag which if True will cause a summary to be printed. 149 @type summary: bool 150 """ 151 152 # Print a header. 153 title('Unit tests') 154 155 # Run the tests. 156 unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests') 157 self.unit_result = unit_runner.run(runner=self.runner) 158 159 # Print out a summary of the test suite. 160 if summary: 161 self.summary()
162 163
164 - def summary(self):
165 """Print out a summary of the relax test suite.""" 166 167 # Title. 168 title("Summary of the relax test suite") 169 170 # The skipped tests. 171 self.summary_skipped() 172 173 # Subtitle. 174 subtitle("Synopsis") 175 176 # System/functional test summary. 177 if hasattr(self, 'system_result'): 178 summary_line("System/functional tests", self.system_result) 179 180 # Unit test summary. 181 if hasattr(self, 'unit_result'): 182 summary_line("Unit tests", self.unit_result) 183 184 # GUI test summary. 185 if hasattr(self, 'gui_result'): 186 summary_line("GUI tests", self.gui_result) 187 188 # Synopsis. 189 if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result'): 190 summary_line("Synopsis", self.system_result and self.unit_result and self.gui_result) 191 192 # End. 193 print('\n\n')
194 195
196 - def summary_skipped(self):
197 """Print out information about skipped tests.""" 198 199 # Counts. 200 system_count = {} 201 unit_count = {} 202 gui_count = {} 203 for i in range(len(status.skipped_tests)): 204 # Alias. 205 test = status.skipped_tests[i] 206 207 # Initialise in needed. 208 if not system_count.has_key(test[1]): 209 system_count[test[1]] = 0 210 unit_count[test[1]] = 0 211 gui_count[test[1]] = 0 212 213 # A system test. 214 if test[2] == 'system': 215 system_count[test[1]] += 1 216 217 # A unit test. 218 if test[2] == 'unit': 219 unit_count[test[1]] += 1 220 221 # A GUI test. 222 if test[2] == 'gui': 223 gui_count[test[1]] += 1 224 225 # The missing modules. 226 missing_modules = sorted(system_count.keys()) 227 subtitle("Optional packages/modules") 228 229 # Nothing missing. 230 if not missing_modules: 231 # Print out. 232 print("No tests skipped due to missing modules.\n") 233 234 # The skip the table. 235 return 236 237 # Header. 238 print("Tests skipped due to missing packages/modules:\n") 239 header = "%-30s" % "Module" 240 if hasattr(self, 'system_result'): 241 header = "%s %20s" % (header, "System test count") 242 if hasattr(self, 'unit_result'): 243 header = "%s %20s" % (header, "Unit test count") 244 if hasattr(self, 'gui_result'): 245 header = "%s %20s" % (header, "GUI test count") 246 print('-'*len(header)) 247 print(header) 248 print('-'*len(header)) 249 250 # The table. 251 for module in missing_modules: 252 text = "%-30s" % module 253 if hasattr(self, 'system_result'): 254 text = "%s %20s" % (text, system_count[module]) 255 if hasattr(self, 'unit_result'): 256 text = "%s %20s" % (text, unit_count[module]) 257 if hasattr(self, 'gui_result'): 258 text = "%s %20s" % (text, gui_count[module]) 259 print(text) 260 261 262 # End the table. 263 print('-'*len(header)) 264 print("\n")
265