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 shutil import rmtree
29 from tempfile import mktemp, mkdtemp
30 from unittest import TestCase
31 import wx
32
33
34 import dep_check
35
36
37 from compat import queue
38 from data import Relax_data_store; ds = Relax_data_store()
39 from data.gui import Gui
40 from generic_fns.reset import reset
41 from prompt.interpreter import exec_script
42 from relax_errors import RelaxError
43 from relax_io import delete
44 from status import Status; status = Status()
45 from user_functions.data import Uf_info; uf_info = Uf_info()
46
47
48 from gui.interpreter import Interpreter; interpreter = Interpreter()
49 from gui.wizard import Wiz_window
50 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
51
52
54 """The GUI test base class."""
55
57 """Set up the test case class for the system tests."""
58
59
60 if not hasattr(self, '_skip_type'):
61 self._skip_type = 'gui'
62
63
64 super(GuiTestCase, self).__init__(methodName)
65
66
68 """Execute the given user function.
69
70 @keyword uf_name: The name of the user function.
71 @type uf_name: str
72 """
73
74
75 if 'uf_name' not in kargs:
76 raise RelaxError("The user function name argument 'uf_name' has not been supplied.")
77
78
79 uf_name = kargs.pop('uf_name')
80
81
82 uf_data = uf_info.get_uf(uf_name)
83
84
85 for i in range(len(args)):
86
87 name = uf_data.kargs[i]['name']
88
89
90 if name in kargs:
91 raise RelaxError("The argument '%s' clashes with the %s keyword argument of '%s'." % (arg[i], name, kargs[name]))
92
93
94 kargs[name] = args[i]
95
96
97 for i in range(len(uf_data.kargs)):
98
99 arg = uf_data.kargs[i]
100
101
102 if arg['name'] in kargs:
103 continue
104
105
106 kargs[arg['name']] = arg['default']
107
108
109 for i in range(len(uf_data.kargs)):
110
111 arg = uf_data.kargs[i]
112
113
114 if arg['arg_type'] == 'dir' and arg['name'] in kargs:
115
116 for j in range(len(uf_data.kargs)):
117 if uf_data.kargs[j]['arg_type'] == 'file sel':
118 file_sel_name = uf_data.kargs[j]['name']
119
120
121 if file_sel_name in kargs and kargs[arg['name']]:
122 kargs[file_sel_name] = kargs[arg['name']] + sep + kargs[file_sel_name]
123
124
125 kargs.pop(arg['name'])
126
127
128 uf = uf_store[uf_name]
129
130
131 status.gui_uf_force_sync = True
132
133
134 uf(wx_wizard_run=False, **kargs)
135
136
137 uf.wizard._ok()
138
139
140 status.gui_uf_force_sync = False
141
142
144 """Check that no exception has occurred."""
145
146
147 try:
148
149 index, exc = status.exception_queue.get(block=False)
150
151
152 print("Exception found, failing the test with an AssertionError:\n")
153
154
155 self.fail()
156
157
158 except queue.Empty:
159 pass
160
161
163 """Execute a GUI script within the GUI test framework.
164
165 @param script: The full path of the script to execute.
166 @type script: str
167 """
168
169
170 space = locals()
171
172
173 space.update({'pi': pi})
174
175
176 exec_script(script, space)
177
178
180 """Set up for all the functional tests."""
181
182
183 ds.tmpfile = mktemp()
184
185
186 ds.tmpdir = mkdtemp()
187
188
189 self.app = wx.GetApp()
190
191
193 """Default tearDown operation - delete temp directories and files and reset relax."""
194
195
196 wx.Yield()
197
198
199 if hasattr(ds, 'tmpdir'):
200
201 rmtree(ds.tmpdir)
202
203
204 del ds.tmpdir
205
206
207 if hasattr(self, 'tmpdir'):
208
209 rmtree(self.tmpdir)
210
211
212 del self.tmpdir
213
214
215 if hasattr(ds, 'tmpfile'):
216
217 delete(ds.tmpfile, fail=False)
218
219
220 del ds.tmpfile
221
222
223 if hasattr(self, 'tmpfile'):
224
225 delete(self.tmpfile, fail=False)
226
227
228 del self.tmpfile
229
230
231 reset()
232