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 dep_check
25
26
27 import os
28 import sys
29 from traceback import print_exc
30 if dep_check.wx_module:
31 import wx
32 import unittest
33
34
35 from test_suite.formatting import summary_line
36
37
38 if dep_check.wx_module:
39 from test_suite.gui_tests import GUI_test_runner
40 from test_suite.system_tests import System_test_runner
41 from test_suite.unit_tests.unit_test_runner import Unit_test_runner
42 from test_suite.verification_tests import Verification_test_runner
43
44
45 if dep_check.wx_module:
46 from gui import relax_gui
47 from gui import interpreter
48 from lib.text.sectioning import section, title
49 from test_suite.relax_test_runner import GuiTestRunner, RelaxTestRunner
50 from status import Status; status = Status()
51
52
54 """Class for running all components of the relax test suite.
55
56 This currently includes the following categories of tests:
57 - System/functional tests.
58 - Unit tests.
59 - GUI tests.
60 - Verification tests.
61 """
62
63 - def __init__(self, tests=[], from_gui=False, categories=['system', 'unit', 'gui', 'verification'], timing=False):
64 """Store the list of tests to preform.
65
66 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.
67
68
69 @keyword tests: The list of tests to preform. If left at [], then all tests will be run.
70 @type tests: list of str
71 @keyword from_gui: A flag which indicates if the tests are being run from the GUI or not.
72 @type from_gui: bool
73 @keyword categories: The list of test categories to run, for example ['system', 'unit', 'gui', 'verification'] for all tests.
74 @type categories: list of str
75 @keyword timing: A flag which if True will enable timing of individual tests.
76 @type timing: bool
77 """
78
79
80 self.tests = tests
81 self.from_gui = from_gui
82 self.categories = categories
83
84
85 if from_gui:
86 self.runner = GuiTestRunner(stream=sys.stdout, timing=timing)
87 else:
88 self.runner = RelaxTestRunner(stream=sys.stdout, timing=timing)
89
90
91 if hasattr(unittest, 'installHandler'):
92 unittest.installHandler()
93
94
96 """Execute all of the test suite test types.
97
98 @keyword reset: A flag which if True will reset the relax status objects for the tests.
99 @type reset: bool
100 @return: The combined status of the test categories.
101 @rtype: bool
102 """
103
104
105 if reset:
106 status.skipped_tests = []
107
108
109 test_status = True
110
111
112 if 'system' in self.categories:
113 test_status = self.run_system_tests(summary=False, reset=False) and test_status
114
115
116 if 'unit' in self.categories:
117 test_status = self.run_unit_tests(summary=False, reset=False) and test_status
118
119
120 if 'gui' in self.categories:
121 test_status = self.run_gui_tests(summary=False, reset=False) and test_status
122
123
124 if 'verification' in self.categories:
125 test_status = self.run_verification_tests(summary=False, reset=False) and test_status
126
127
128 self.summary()
129 return test_status
130
131
133 """Execute the GUI tests.
134
135 @keyword summary: A flag which if True will cause a summary to be printed.
136 @type summary: bool
137 @keyword reset: A flag which if True will reset the relax status objects for the tests.
138 @type reset: bool
139 @return: True if the tests were run, False if a KeyboardInterrupt occurred.
140 @rtype: bool
141 """
142
143
144 if reset:
145 status.skipped_tests = []
146
147
148 try:
149
150 title(file=sys.stdout, text='GUI tests')
151
152
153 if dep_check.wx_module:
154
155 app = wx.GetApp()
156 if app == None:
157
158 app = wx.App(redirect=False)
159
160
161 app.gui = relax_gui.Main(parent=None, id=-1, title="")
162
163
164 gui_runner = GUI_test_runner()
165 self.runner.category = 'gui'
166 self.gui_result = gui_runner.run(self.tests, runner=self.runner)
167
168
169 if status.test_mode:
170
171 interpreter_thread = interpreter.Interpreter()
172 interpreter_thread.exit()
173
174
175 app.ExitMainLoop()
176
177
178 else:
179 print("All GUI tests skipped due to the missing/broken wx module.\n")
180 self.gui_result = 'skip'
181
182
183 if summary:
184 self.summary()
185
186
187 except KeyboardInterrupt:
188 print("\nKeyboardInterrupt: Terminating all tests.\n")
189 sys.exit(1)
190
191
192 except:
193 print("Failure in setting up the GUI tests.\n")
194 print_exc()
195 if summary:
196 self.summary()
197 self.gui_result = 'skip'
198 return False
199
200
201 return self.gui_result
202
203
205 """Execute the system/functional tests.
206
207 @keyword summary: A flag which if True will cause a summary to be printed.
208 @type summary: bool
209 @keyword reset: A flag which if True will reset the relax status objects for the tests.
210 @type reset: bool
211 @return: True if the tests were run, False if a KeyboardInterrupt occurred.
212 @rtype: bool
213 """
214
215
216 if reset:
217 status.skipped_tests = []
218
219
220 try:
221
222 title(file=sys.stdout, text='System / functional tests')
223
224
225 system_runner = System_test_runner()
226 self.runner.category = 'system'
227 self.system_result = system_runner.run(self.tests, runner=self.runner)
228
229
230 if summary:
231 self.summary()
232
233
234 except KeyboardInterrupt:
235 print("\nKeyboardInterrupt: Terminating all tests.\n")
236 sys.exit(1)
237
238
239 return self.system_result
240
241
243 """Execute the unit tests.
244
245 @keyword summary: A flag which if True will cause a summary to be printed.
246 @type summary: bool
247 @keyword reset: A flag which if True will reset the relax status objects for the tests.
248 @type reset: bool
249 @return: True if the tests were run, False if a KeyboardInterrupt occurred.
250 @rtype: bool
251 """
252
253
254 if reset:
255 status.skipped_tests = []
256
257
258 try:
259
260 title(file=sys.stdout, text='Unit tests')
261
262
263 unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests')
264 self.runner.category = 'unit'
265 self.unit_result = unit_runner.run(self.tests, runner=self.runner)
266
267
268 if summary:
269 self.summary()
270
271
272 except KeyboardInterrupt:
273 print("\nKeyboardInterrupt: Terminating all tests.\n")
274 sys.exit(1)
275
276
277 return self.unit_result
278
279
281 """Execute the software verification tests.
282
283 @keyword summary: A flag which if True will cause a summary to be printed.
284 @type summary: bool
285 @keyword reset: A flag which if True will reset the relax status objects for the tests.
286 @type reset: bool
287 """
288
289
290 if reset:
291 status.skipped_tests = []
292
293
294 try:
295
296 title(file=sys.stdout, text='Software verification tests')
297
298
299 verification_runner = Verification_test_runner()
300 self.runner.category = 'verification'
301 self.verification_result = verification_runner.run(self.tests, runner=self.runner)
302
303
304 if summary:
305 self.summary()
306
307
308 except KeyboardInterrupt:
309 print("\nKeyboardInterrupt: Terminating all tests.\n")
310 sys.exit(1)
311
312
313 return self.verification_result
314
315
317 """Print out a summary of the relax test suite."""
318
319
320 title(file=sys.stdout, text="Summary of the relax test suite")
321
322
323 if status.skip_blacklisted_tests:
324 self.summary_skipped()
325
326
327 section(file=sys.stdout, text="Synopsis")
328
329
330 if hasattr(self, 'system_result'):
331 summary_line("System/functional tests", self.system_result)
332
333
334 if hasattr(self, 'unit_result'):
335 summary_line("Unit tests", self.unit_result)
336
337
338 if hasattr(self, 'gui_result'):
339 summary_line("GUI tests", self.gui_result)
340
341
342 if hasattr(self, 'verification_result'):
343 summary_line("Software verification tests", self.verification_result)
344
345
346 if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result') and hasattr(self, 'verification_result'):
347 if self.gui_result == "skip":
348 test_status = self.system_result and self.unit_result and self.verification_result
349 else:
350 test_status = self.system_result and self.unit_result and self.gui_result and self.verification_result
351 summary_line("Synopsis", test_status)
352
353
354 print('\n\n')
355
356
358 """Print out information about skipped tests."""
359
360
361 system_count = {}
362 unit_count = {}
363 gui_count = {}
364 verification_count = {}
365 for i in range(len(status.skipped_tests)):
366
367 test = status.skipped_tests[i]
368
369
370 if test[1] == None:
371 continue
372
373
374 if not test[1] in system_count:
375 system_count[test[1]] = 0
376 unit_count[test[1]] = 0
377 gui_count[test[1]] = 0
378 verification_count[test[1]] = 0
379
380
381 if test[2] == 'system':
382 system_count[test[1]] += 1
383
384
385 if test[2] == 'unit':
386 unit_count[test[1]] += 1
387
388
389 if test[2] == 'gui':
390 gui_count[test[1]] += 1
391
392
393 if test[2] == 'verification':
394 verification_count[test[1]] += 1
395
396
397 missing_modules = sorted(system_count.keys())
398 section(file=sys.stdout, text="Optional packages/modules")
399
400
401 if not missing_modules:
402
403 if not dep_check.wx_module and hasattr(self, 'gui_result'):
404 print("All GUI tests skipped due to the missing wxPython module, no other tests skipped due to missing modules.\n")
405
406
407 else:
408 print("No tests skipped due to missing modules.\n")
409
410
411 return
412
413
414 print("Tests skipped due to missing optional packages/modules/software:\n")
415 header = "%-33s" % "Module/package/software"
416 if len(system_count):
417 header = "%s %20s" % (header, "System test count")
418 if len(unit_count):
419 header = "%s %20s" % (header, "Unit test count")
420 if len(gui_count):
421 header = "%s %20s" % (header, "GUI test count")
422 if len(verification_count):
423 header = "%s %20s" % (header, "Verification test count")
424 print('-'*len(header))
425 print(header)
426 print('-'*len(header))
427
428
429 for module in missing_modules:
430 text = "%-33s" % module
431 if len(system_count):
432 text = "%s %20s" % (text, system_count[module])
433 if len(unit_count):
434 text = "%s %20s" % (text, unit_count[module])
435 if len(gui_count):
436 text = "%s %20s" % (text, gui_count[module])
437 if len(verification_count):
438 text = "%s %20s" % (text, verification_count[module])
439 print(text)
440
441
442 print('-'*len(header))
443 print("\n")
444