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 try:
29 import queue
30 except ImportError:
31 import Queue as queue
32 from shutil import rmtree
33 from tempfile import mktemp, mkdtemp
34 from unittest import TestCase
35 import wx
36
37
38 import dep_check
39
40
41 from data import Relax_data_store; ds = Relax_data_store()
42 from data.gui import Gui
43 from generic_fns.reset import reset
44 from prompt.interpreter import exec_script
45 from relax_errors import RelaxError
46 from relax_io import delete
47 from status import Status; status = Status()
48 from user_functions.data import Uf_info; uf_info = Uf_info()
49
50
51 from gui.interpreter import Interpreter; interpreter = Interpreter()
52 from gui.wizard import Wiz_window
53 from gui.uf_objects import Uf_storage; uf_store = Uf_storage()
54
55
57 """The GUI test base class."""
58
60 """Set up the test case class for the system tests."""
61
62
63 if not hasattr(self, '_skip_type'):
64 self._skip_type = 'gui'
65
66
67 super(GuiTestCase, self).__init__(methodName)
68
69
71 """Execute the given user function.
72
73 @keyword uf_name: The name of the user function.
74 @type uf_name: str
75 """
76
77
78 if 'uf_name' not in kargs:
79 raise RelaxError("The user function name argument 'uf_name' has not been supplied.")
80
81
82 uf_name = kargs.pop('uf_name')
83
84
85 uf_data = uf_info.get_uf(uf_name)
86
87
88 for i in range(len(args)):
89
90 name = uf_data.kargs[i]['name']
91
92
93 if name in kargs:
94 raise RelaxError("The argument '%s' clashes with the %s keyword argument of '%s'." % (arg[i], name, kargs[name]))
95
96
97 kargs[name] = args[i]
98
99
100 for i in range(len(uf_data.kargs)):
101
102 arg = uf_data.kargs[i]
103
104
105 if arg['name'] in kargs:
106 continue
107
108
109 kargs[arg['name']] = arg['default']
110
111
112 for i in range(len(uf_data.kargs)):
113
114 arg = uf_data.kargs[i]
115
116
117 if arg['arg_type'] == 'dir' and arg['name'] in kargs:
118
119 for j in range(len(uf_data.kargs)):
120 if uf_data.kargs[j]['arg_type'] == 'file sel':
121 file_sel_name = uf_data.kargs[j]['name']
122
123
124 if file_sel_name in kargs and kargs[arg['name']]:
125 kargs[file_sel_name] = kargs[arg['name']] + sep + kargs[file_sel_name]
126
127
128 kargs.pop(arg['name'])
129
130
131 uf = uf_store[uf_name]
132
133
134 status.gui_uf_force_sync = True
135
136
137 uf(wx_wizard_run=False, **kargs)
138
139
140 uf.wizard._ok()
141
142
143 status.gui_uf_force_sync = False
144
145
147 """Check that no exception has occurred."""
148
149
150 try:
151
152 index, exc = status.exception_queue.get(block=False)
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