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
31
32 from test_suite.formatting import summary_line
33
34
35 if dep_check.wx_module:
36 from test_suite.gui_tests import GUI_test_runner
37 from test_suite.system_tests import System_test_runner
38 from test_suite.unit_tests.unit_test_runner import Unit_test_runner
39
40
41 if dep_check.wx_module:
42 from gui import relax_gui
43 from gui import interpreter
44 from lib.text.sectioning import section, title
45 from test_suite.relax_test_runner import GuiTestRunner, RelaxTestRunner
46 from status import Status; status = Status()
47
48
50 """Class for running all components of the relax test suite.
51
52 This currently includes the following categories of tests:
53 - System/functional tests.
54 - Unit tests.
55 - GUI tests.
56 """
57
58 - def __init__(self, tests=[], from_gui=False, categories=['system', 'unit', 'gui'], timing=False):
59 """Store the list of tests to preform.
60
61 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.
62
63
64 @keyword tests: The list of tests to preform. If left at [], then all tests will be run.
65 @type tests: list of str
66 @keyword from_gui: A flag which indicates if the tests are being run from the GUI or not.
67 @type from_gui: bool
68 @keyword categories: The list of test categories to run, for example ['system', 'unit', 'gui'] for all tests.
69 @type categories: list of str
70 @keyword timing: A flag which if True will enable timing of individual tests.
71 @type timing: bool
72 """
73
74
75 self.tests = tests
76 self.from_gui = from_gui
77 self.categories = categories
78
79
80 status.skip = []
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
106
107
109 """Execute the GUI tests.
110
111 @keyword summary: A flag which if True will cause a summary to be printed.
112 @type summary: bool
113 """
114
115
116 title(file=sys.stdout, text='GUI tests')
117
118
119 if dep_check.wx_module:
120
121 app = wx.GetApp()
122 if app == None:
123
124 app = wx.App(redirect=False)
125
126
127 app.gui = relax_gui.Main(parent=None, id=-1, title="")
128
129
130 gui_runner = GUI_test_runner()
131 self.gui_result = gui_runner.run(self.tests, runner=self.runner)
132
133
134 if status.test_mode:
135
136 interpreter_thread = interpreter.Interpreter()
137 interpreter_thread.exit()
138
139
140 app.ExitMainLoop()
141
142
143 else:
144 print("All GUI tests skipped due to the missing/broken wx module.\n")
145 self.gui_result = 'skip'
146
147
148 if summary:
149 self.summary()
150
151
153 """Execute the system/functional tests.
154
155 @keyword summary: A flag which if True will cause a summary to be printed.
156 @type summary: bool
157 """
158
159
160 title(file=sys.stdout, text='System / functional tests')
161
162
163 system_runner = System_test_runner()
164 self.system_result = system_runner.run(self.tests, runner=self.runner)
165
166
167 if summary:
168 self.summary()
169
170
172 """Execute the unit tests.
173
174 @keyword summary: A flag which if True will cause a summary to be printed.
175 @type summary: bool
176 """
177
178
179 title(file=sys.stdout, text='Unit tests')
180
181
182 unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests')
183 self.unit_result = unit_runner.run(runner=self.runner)
184
185
186 if summary:
187 self.summary()
188
189
191 """Print out a summary of the relax test suite."""
192
193
194 title(file=sys.stdout, text="Summary of the relax test suite")
195
196
197 self.summary_skipped()
198
199
200 section(file=sys.stdout, text="Synopsis")
201
202
203 if hasattr(self, 'system_result'):
204 summary_line("System/functional tests", self.system_result)
205
206
207 if hasattr(self, 'unit_result'):
208 summary_line("Unit tests", self.unit_result)
209
210
211 if hasattr(self, 'gui_result'):
212 summary_line("GUI tests", self.gui_result)
213
214
215 if hasattr(self, 'system_result') and hasattr(self, 'unit_result') and hasattr(self, 'gui_result'):
216 if self.gui_result == "skip":
217 status = self.system_result and self.unit_result
218 else:
219 status = self.system_result and self.unit_result and self.gui_result
220 summary_line("Synopsis", status)
221
222
223 print('\n\n')
224
225
227 """Print out information about skipped tests."""
228
229
230 system_count = {}
231 unit_count = {}
232 gui_count = {}
233 for i in range(len(status.skipped_tests)):
234
235 test = status.skipped_tests[i]
236
237
238 if test[1] == None:
239 continue
240
241
242 if not test[1] in system_count:
243 system_count[test[1]] = 0
244 unit_count[test[1]] = 0
245 gui_count[test[1]] = 0
246
247
248 if test[2] == 'system':
249 system_count[test[1]] += 1
250
251
252 if test[2] == 'unit':
253 unit_count[test[1]] += 1
254
255
256 if test[2] == 'gui':
257 gui_count[test[1]] += 1
258
259
260 missing_modules = sorted(system_count.keys())
261 section(file=sys.stdout, text="Optional packages/modules")
262
263
264 if not missing_modules:
265
266 if not dep_check.wx_module and hasattr(self, 'gui_result'):
267 print("All GUI tests skipped due to the missing wxPython module, no other tests skipped due to missing modules.\n")
268
269
270 else:
271 print("No tests skipped due to missing modules.\n")
272
273
274 return
275
276
277 print("Tests skipped due to missing packages/modules:\n")
278 header = "%-30s" % "Module"
279 if len(system_count):
280 header = "%s %20s" % (header, "System test count")
281 if len(unit_count):
282 header = "%s %20s" % (header, "Unit test count")
283 if len(gui_count):
284 header = "%s %20s" % (header, "GUI test count")
285 print('-'*len(header))
286 print(header)
287 print('-'*len(header))
288
289
290 for module in missing_modules:
291 text = "%-30s" % module
292 if len(system_count):
293 text = "%s %20s" % (text, system_count[module])
294 if len(unit_count):
295 text = "%s %20s" % (text, unit_count[module])
296 if len(gui_count):
297 text = "%s %20s" % (text, gui_count[module])
298 print(text)
299
300
301
302 print('-'*len(header))
303 print("\n")
304