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