1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Base classes for the GUI tests."""
24
25
26 from math import pi
27 from os import sep
28 from tempfile import mkdtemp, mkstemp
29 from unittest import TestCase
30 import wx
31
32
33 from data_store import Relax_data_store; ds = Relax_data_store()
34 from gui.controller import Controller
35 from gui.relax_gui import Main
36 from gui.string_conv import str_to_gui
37 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
38 from gui.wizards.wiz_objects import Wiz_window
39 from lib.compat import queue
40 from lib.errors import RelaxError
41 from pipe_control.reset import reset
42 from prompt.interpreter import exec_script
43 from status import Status; status = Status()
44 from test_suite.clean_up import deletion
45 from user_functions.data import Uf_info; uf_info = Uf_info()
46
47
49 """The GUI test base class."""
50
52 """Set up the test case class for the system tests."""
53
54
55 if not hasattr(self, '_skip_type'):
56 self._skip_type = 'gui'
57
58
59 super(GuiTestCase, self).__init__(methodName)
60
61
63 """Execute the given user function.
64
65 @keyword uf_name: The name of the user function.
66 @type uf_name: str
67 """
68
69
70 if 'uf_name' not in kargs:
71 raise RelaxError("The user function name argument 'uf_name' has not been supplied.")
72
73
74 uf_name = kargs.pop('uf_name')
75
76
77 uf_data = uf_info.get_uf(uf_name)
78
79
80 for i in range(len(args)):
81
82 name = uf_data.kargs[i]['name']
83
84
85 if name in kargs:
86 raise RelaxError("The argument '%s' clashes with the %s keyword argument of '%s'." % (arg[i], name, kargs[name]))
87
88
89 kargs[name] = args[i]
90
91
92 for i in range(len(uf_data.kargs)):
93
94 arg = uf_data.kargs[i]
95
96
97 if arg['name'] in kargs:
98 continue
99
100
101 kargs[arg['name']] = arg['default']
102
103
104 for i in range(len(uf_data.kargs)):
105
106 arg = uf_data.kargs[i]
107
108
109 if arg['arg_type'] == 'dir' and arg['name'] in kargs:
110
111 for j in range(len(uf_data.kargs)):
112 if uf_data.kargs[j]['arg_type'] in ['file sel read', 'file sel write']:
113 file_sel_name = uf_data.kargs[j]['name']
114
115
116 if file_sel_name in kargs and kargs[arg['name']]:
117 kargs[file_sel_name] = kargs[arg['name']] + sep + kargs[file_sel_name]
118
119
120 kargs.pop(arg['name'])
121
122
123 uf = uf_store[uf_name]
124
125
126 status.gui_uf_force_sync = True
127
128
129 uf(wx_wizard_run=False, **kargs)
130
131
132 uf.wizard._ok()
133
134
135 status.gui_uf_force_sync = False
136
137
138 uf.Destroy()
139
140
142 """Check that no exception has occurred."""
143
144
145 try:
146
147 index, exc = status.exception_queue.get(block=False)
148
149
150 print("Exception found, failing the test with an AssertionError:\n")
151
152
153 self.fail()
154
155
156 except queue.Empty:
157 pass
158
159
199
200
201 - def new_analysis_wizard(self, analysis_type=None, analysis_name=None, pipe_name=None, pipe_bundle=None):
202 """Simulate the new analysis wizard, and return the analysis page.
203
204 @keyword analysis_type: The type of the analysis to use in the first wizard page.
205 @type analysis_type: str
206 @keyword analysis_name: The name of the analysis to use in the first wizard page.
207 @type analysis_name: str
208 @keyword pipe_name: The name of the data pipe to create, if different from the default.
209 @type pipe_name: None or str
210 @keyword pipe_bundle: The name of the data pipe bundle to create, if different from the default.
211 @type pipe_bundle: None or str
212 """
213
214
215 self.app.gui.analysis.menu_new(None, destroy=False)
216
217
218 page = self.app.gui.analysis.new_wizard.wizard.get_page(0)
219 if analysis_type == 'noe':
220 page.select_noe(None)
221 elif analysis_type == 'r1':
222 page.select_r1(None)
223 elif analysis_type == 'r2':
224 page.select_r2(None)
225 elif analysis_type == 'mf':
226 page.select_mf(None)
227 elif analysis_type == 'disp':
228 page.select_disp(None)
229 else:
230 raise RelaxError("Unknown analysis type '%s'." % analysis_type)
231 if analysis_name:
232 page.analysis_name.SetValue(str_to_gui(analysis_name))
233 self.app.gui.analysis.new_wizard.wizard._go_next(None)
234
235
236 page = self.app.gui.analysis.new_wizard.wizard.get_page(1)
237 if pipe_name:
238 page.pipe_name.SetValue(str_to_gui(pipe_name))
239 if pipe_bundle:
240 page.pipe_bundle.SetValue(str_to_gui(pipe_bundle))
241 self.app.gui.analysis.new_wizard.wizard._go_next(None)
242
243
244 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data()
245
246
247 wx.Yield()
248 self.app.gui.analysis.new_wizard.Destroy()
249 del self.app.gui.analysis.new_wizard
250
251
252 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle)
253
254
255 return self.app.gui.analysis.get_page_from_name(analysis_name)
256
257
259 """Execute a GUI script within the GUI test framework.
260
261 @param script: The full path of the script to execute.
262 @type script: str
263 """
264
265
266 space = locals()
267
268
269 space.update({'pi': pi})
270
271
272 exec_script(script, space)
273
274
276 """Set up for all the functional tests."""
277
278
279 ds.tmpfile_handle, ds.tmpfile = mkstemp()
280
281
282 ds.tmpdir = mkdtemp()
283
284
285 self.app = wx.GetApp()
286
287
289 """Default tearDown operation - delete temp directories and files and reset relax."""
290
291
292 wx.Yield()
293
294
295 deletion(obj=ds, name='tmpdir', dir=True)
296 deletion(obj=self, name='tmpdir', dir=True)
297
298
299 deletion(obj=ds, name='tmpfile', dir=False)
300 deletion(obj=self, name='tmpfile', dir=False)
301
302
303 reset()
304
305
306 self.app = wx.GetApp()
307
308
309 self.clean_up_windows()
310
311
312 print("\n\nList of all living GUI elements - this must only include the main GUI window and the relax controller:")
313 all_destroyed = True
314 for window in wx.GetTopLevelWindows():
315
316 print(" Window: %s" % window)
317 if isinstance(window, Wiz_window):
318 print(" Wizard title: %s" % window.title)
319 print(" Wizard pages: %s" % window._pages)
320
321
322 if isinstance(window, Main) or isinstance(window, Controller):
323 continue
324
325
326 all_destroyed = False
327 print("\n\n\n")
328
329
330
331
332