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