1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  import os 
 25  import sys 
 26   
 27   
 28  import dep_check 
 29   
 30   
 31  from formatting import subtitle, summary_line, title 
 32   
 33   
 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   
 40  from relax_test_runner import GuiTestRunner, RelaxTestRunner 
 41  from status import Status; status = Status() 
 42   
 43   
 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           
 68          self.tests = tests 
 69          self.from_gui = from_gui 
 70          self.categories = categories 
 71   
 72           
 73          status.skip = [] 
 74   
 75           
 76          if from_gui: 
 77              self.runner = GuiTestRunner(stream=sys.stdout) 
 78          else: 
 79              self.runner = RelaxTestRunner(stream=sys.stdout) 
  80   
 81   
 99   
100   
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           
109          title('GUI tests') 
110   
111           
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           
117          else: 
118              print("All GUI tests skipped due to the missing/broken wx module.\n") 
119              self.gui_result = 'skip' 
120   
121           
122          if summary: 
123              self.summary() 
 124   
125   
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           
134          title('System / functional tests') 
135   
136           
137          system_runner = System_test_runner() 
138          self.system_result = system_runner.run(self.tests, runner=self.runner) 
139   
140           
141          if summary: 
142              self.summary() 
 143   
144   
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           
153          title('Unit tests') 
154   
155           
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           
160          if summary: 
161              self.summary() 
 162   
163   
165          """Print out a summary of the relax test suite.""" 
166   
167           
168          title("Summary of the relax test suite") 
169   
170           
171          self.summary_skipped() 
172   
173           
174          subtitle("Synopsis") 
175   
176           
177          if hasattr(self, 'system_result'): 
178              summary_line("System/functional tests", self.system_result) 
179   
180           
181          if hasattr(self, 'unit_result'): 
182              summary_line("Unit tests", self.unit_result) 
183   
184           
185          if hasattr(self, 'gui_result'): 
186              summary_line("GUI tests", self.gui_result) 
187   
188           
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           
193          print('\n\n') 
 194   
195   
197          """Print out information about skipped tests."""  
198   
199           
200          system_count = {} 
201          unit_count = {} 
202          gui_count = {} 
203          for i in range(len(status.skipped_tests)): 
204               
205              test = status.skipped_tests[i] 
206   
207               
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               
214              if test[2] == 'system': 
215                  system_count[test[1]] += 1 
216   
217               
218              if test[2] == 'unit': 
219                  unit_count[test[1]] += 1 
220   
221               
222              if test[2] == 'gui': 
223                  gui_count[test[1]] += 1 
224   
225           
226          missing_modules = sorted(system_count.keys()) 
227          subtitle("Optional packages/modules") 
228   
229           
230          if not missing_modules: 
231               
232              print("No tests skipped due to missing modules.\n") 
233   
234               
235              return 
236   
237           
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           
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           
263          print('-'*len(header)) 
264          print("\n") 
  265