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