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(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 self.summary_skipped()
287
288
289 section(file=sys.stdout, text="Synopsis")
290
291
292 if hasattr(self, 'system_result'):
293 summary_line("System/functional tests", self.system_result)
294
295
296 if hasattr(self, 'unit_result'):
297 summary_line("Unit tests", self.unit_result)
298
299
300 if hasattr(self, 'gui_result'):
301 summary_line("GUI tests", self.gui_result)
302
303
304 if hasattr(self, 'verification_result'):
305 summary_line("Software verification tests", self.verification_result)
306
307
308 if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result') and hasattr(self, 'verification_result'):
309 if self.gui_result == "skip":
310 status = self.system_result and self.unit_result and self.verification_result
311 else:
312 status = self.system_result and self.unit_result and self.gui_result and self.verification_result
313 summary_line("Synopsis", status)
314
315
316 print('\n\n')
317
318
320 """Print out information about skipped tests."""
321
322
323 system_count = {}
324 unit_count = {}
325 gui_count = {}
326 verification_count = {}
327 for i in range(len(status.skipped_tests)):
328
329 test = status.skipped_tests[i]
330
331
332 if test[1] == None:
333 continue
334
335
336 if not test[1] in system_count:
337 system_count[test[1]] = 0
338 unit_count[test[1]] = 0
339 gui_count[test[1]] = 0
340 verification_count[test[1]] = 0
341
342
343 if test[2] == 'system':
344 system_count[test[1]] += 1
345
346
347 if test[2] == 'unit':
348 unit_count[test[1]] += 1
349
350
351 if test[2] == 'gui':
352 gui_count[test[1]] += 1
353
354
355 if test[2] == 'verification':
356 verification_count[test[1]] += 1
357
358
359 missing_modules = sorted(system_count.keys())
360 section(file=sys.stdout, text="Optional packages/modules")
361
362
363 if not missing_modules:
364
365 if not dep_check.wx_module and hasattr(self, 'gui_result'):
366 print("All GUI tests skipped due to the missing wxPython module, no other tests skipped due to missing modules.\n")
367
368
369 else:
370 print("No tests skipped due to missing modules.\n")
371
372
373 return
374
375
376 print("Tests skipped due to missing packages/modules:\n")
377 header = "%-30s" % "Module"
378 if len(system_count):
379 header = "%s %20s" % (header, "System test count")
380 if len(unit_count):
381 header = "%s %20s" % (header, "Unit test count")
382 if len(gui_count):
383 header = "%s %20s" % (header, "GUI test count")
384 if len(verification_count):
385 header = "%s %20s" % (header, "Verification test count")
386 print('-'*len(header))
387 print(header)
388 print('-'*len(header))
389
390
391 for module in missing_modules:
392 text = "%-30s" % module
393 if len(system_count):
394 text = "%s %20s" % (text, system_count[module])
395 if len(unit_count):
396 text = "%s %20s" % (text, unit_count[module])
397 if len(gui_count):
398 text = "%s %20s" % (text, gui_count[module])
399 if len(verification_count):
400 text = "%s %20s" % (text, verification_count[module])
401 print(text)
402
403
404 print('-'*len(header))
405 print("\n")
406