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 status.skip = []
84
85
86 if from_gui:
87 self.runner = GuiTestRunner(stream=sys.stdout, timing=timing)
88 else:
89 self.runner = RelaxTestRunner(stream=sys.stdout, timing=timing)
90
91
92 if hasattr(unittest, 'installHandler'):
93 unittest.installHandler()
94
95
125
126
127
129 """Execute the GUI tests.
130
131 @keyword summary: A flag which if True will cause a summary to be printed.
132 @type summary: bool
133 @return: True if the tests were run, False if a KeyboardInterrupt occurred.
134 @rtype: bool
135 """
136
137
138 try:
139
140 title(file=sys.stdout, text='GUI tests')
141
142
143 if dep_check.wx_module:
144
145 app = wx.GetApp()
146 if app == None:
147
148 app = wx.App(redirect=False)
149
150
151 app.gui = relax_gui.Main(parent=None, id=-1, title="")
152
153
154 gui_runner = GUI_test_runner()
155 self.runner.category = 'gui'
156 self.gui_result = gui_runner.run(self.tests, runner=self.runner)
157
158
159 if status.test_mode:
160
161 interpreter_thread = interpreter.Interpreter()
162 interpreter_thread.exit()
163
164
165 app.ExitMainLoop()
166
167
168 else:
169 print("All GUI tests skipped due to the missing/broken wx module.\n")
170 self.gui_result = 'skip'
171
172
173 if summary:
174 self.summary()
175
176
177 except KeyboardInterrupt:
178 print("\nKeyboardInterrupt: Terminating all tests.\n")
179 return False
180
181
182 return True
183
184
186 """Execute the system/functional tests.
187
188 @keyword summary: A flag which if True will cause a summary to be printed.
189 @type summary: bool
190 @return: True if the tests were run, False if a KeyboardInterrupt occurred.
191 @rtype: bool
192 """
193
194
195 try:
196
197 title(file=sys.stdout, text='System / functional tests')
198
199
200 system_runner = System_test_runner()
201 self.runner.category = 'system'
202 self.system_result = system_runner.run(self.tests, runner=self.runner)
203
204
205 if summary:
206 self.summary()
207
208
209 except KeyboardInterrupt:
210 print("\nKeyboardInterrupt: Terminating all tests.\n")
211 return False
212
213
214 return True
215
216
218 """Execute the unit tests.
219
220 @keyword summary: A flag which if True will cause a summary to be printed.
221 @type summary: bool
222 @return: True if the tests were run, False if a KeyboardInterrupt occurred.
223 @rtype: bool
224 """
225
226
227 try:
228
229 title(file=sys.stdout, text='Unit tests')
230
231
232 unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests')
233 self.runner.category = 'unit'
234 self.unit_result = unit_runner.run(self.tests, runner=self.runner)
235
236
237 if summary:
238 self.summary()
239
240
241 except KeyboardInterrupt:
242 print("\nKeyboardInterrupt: Terminating all tests.\n")
243 return False
244
245
246 return True
247
248
250 """Execute the software verification tests.
251
252 @keyword summary: A flag which if True will cause a summary to be printed.
253 @type summary: bool
254 """
255
256
257 try:
258
259 title(file=sys.stdout, text='Software verification tests')
260
261
262 verification_runner = Verification_test_runner()
263 self.runner.category = 'verification'
264 self.verification_result = verification_runner.run(self.tests, runner=self.runner)
265
266
267 if summary:
268 self.summary()
269
270
271 except KeyboardInterrupt:
272 print("\nKeyboardInterrupt: Terminating all tests.\n")
273 return False
274
275
276 return True
277
278
280 """Print out a summary of the relax test suite."""
281
282
283 title(file=sys.stdout, text="Summary of the relax test suite")
284
285
286 if status.skip_blacklisted_tests:
287 self.summary_skipped()
288
289
290 section(file=sys.stdout, text="Synopsis")
291
292
293 if hasattr(self, 'system_result'):
294 summary_line("System/functional tests", self.system_result)
295
296
297 if hasattr(self, 'unit_result'):
298 summary_line("Unit tests", self.unit_result)
299
300
301 if hasattr(self, 'gui_result'):
302 summary_line("GUI tests", self.gui_result)
303
304
305 if hasattr(self, 'verification_result'):
306 summary_line("Software verification tests", self.verification_result)
307
308
309 if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result') and hasattr(self, 'verification_result'):
310 if self.gui_result == "skip":
311 test_status = self.system_result and self.unit_result and self.verification_result
312 else:
313 test_status = self.system_result and self.unit_result and self.gui_result and self.verification_result
314 summary_line("Synopsis", test_status)
315
316
317 print('\n\n')
318
319
321 """Print out information about skipped tests."""
322
323
324 system_count = {}
325 unit_count = {}
326 gui_count = {}
327 verification_count = {}
328 for i in range(len(status.skipped_tests)):
329
330 test = status.skipped_tests[i]
331
332
333 if test[1] == None:
334 continue
335
336
337 if not test[1] in system_count:
338 system_count[test[1]] = 0
339 unit_count[test[1]] = 0
340 gui_count[test[1]] = 0
341 verification_count[test[1]] = 0
342
343
344 if test[2] == 'system':
345 system_count[test[1]] += 1
346
347
348 if test[2] == 'unit':
349 unit_count[test[1]] += 1
350
351
352 if test[2] == 'gui':
353 gui_count[test[1]] += 1
354
355
356 if test[2] == 'verification':
357 verification_count[test[1]] += 1
358
359
360 missing_modules = sorted(system_count.keys())
361 section(file=sys.stdout, text="Optional packages/modules")
362
363
364 if not missing_modules:
365
366 if not dep_check.wx_module and hasattr(self, 'gui_result'):
367 print("All GUI tests skipped due to the missing wxPython module, no other tests skipped due to missing modules.\n")
368
369
370 else:
371 print("No tests skipped due to missing modules.\n")
372
373
374 return
375
376
377 print("Tests skipped due to missing optional packages/modules/software:\n")
378 header = "%-33s" % "Module/package/software"
379 if len(system_count):
380 header = "%s %20s" % (header, "System test count")
381 if len(unit_count):
382 header = "%s %20s" % (header, "Unit test count")
383 if len(gui_count):
384 header = "%s %20s" % (header, "GUI test count")
385 if len(verification_count):
386 header = "%s %20s" % (header, "Verification test count")
387 print('-'*len(header))
388 print(header)
389 print('-'*len(header))
390
391
392 for module in missing_modules:
393 text = "%-33s" % module
394 if len(system_count):
395 text = "%s %20s" % (text, system_count[module])
396 if len(unit_count):
397 text = "%s %20s" % (text, unit_count[module])
398 if len(gui_count):
399 text = "%s %20s" % (text, gui_count[module])
400 if len(verification_count):
401 text = "%s %20s" % (text, verification_count[module])
402 print(text)
403
404
405 print('-'*len(header))
406 print("\n")
407