Package test_suite :: Package gui_tests :: Module test_user_functions
[hide private]
[frames] | no frames]

Source Code for Module test_suite.gui_tests.test_user_functions

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2012-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  """Module for testing the special features of the user function GUI windows.""" 
 23   
 24  # Python module imports. 
 25  from os import sep 
 26   
 27  # relax module imports. 
 28  from status import Status; status = Status() 
 29  from test_suite.gui_tests.base_classes import GuiTestCase 
 30   
 31  # relax GUI imports. 
 32  from gui.interpreter import Interpreter; interpreter = Interpreter() 
 33  from gui.string_conv import float_to_gui, int_to_gui, str_to_gui 
 34  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 35   
 36   
37 -class User_functions(GuiTestCase):
38 """Class for testing special features of the user function GUI windows.""" 39
40 - def exec_uf_pipe_create(self, pipe_name=None, pipe_type='mf'):
41 """Execute the pipe.create user function via the GUI user function window. 42 43 @keyword pipe_name: The pipe_name argument of the pipe.create user function. 44 @type pipe_name: str 45 @keyword pipe_type: The pipe_type argument of the pipe.create user function. 46 @type pipe_type: str 47 """ 48 49 # Open the pipe.create user function window. 50 uf = uf_store['pipe.create'] 51 uf._sync = True 52 uf.create_wizard(parent=self.app.gui) 53 54 # Set the arguments. 55 uf.page.SetValue('pipe_name', str_to_gui(pipe_name)) 56 uf.page.SetValue('pipe_type', str_to_gui(pipe_type)) 57 58 # Execute. 59 uf.wizard._go_next(None)
60 61
62 - def test_dx_map(self):
63 """Test the operation of the dx.map user function GUI window.""" 64 65 # Open the dx.map user function window. 66 uf = uf_store['dx.map'] 67 uf._sync = True 68 uf.create_wizard(parent=self.app.gui) 69 70 # Set the y-value of a single point, and check. 71 uf.page.uf_args['point'].selection_win_show() 72 uf.page.uf_args['point'].sel_win.sequence.SetStringItem(index=0, col=2, label=int_to_gui(2)) 73 uf.page.uf_args['point'].selection_win_data() 74 points = uf.page.uf_args['point'].GetValue() 75 print("Points: %s" % points) 76 self.assertEqual(len(points), 1) 77 self.assertEqual(len(points[0]), 3) 78 self.assertEqual(points[0][0], None) 79 self.assertEqual(points[0][1], 2.0) 80 self.assertEqual(points[0][2], None) 81 82 # Set the point to nothing in the wizard, open the Sequence_2D window, close the window, and check that None comes back. 83 uf.page.uf_args['point'].SetValue(str_to_gui('')) 84 uf.page.uf_args['point'].selection_win_show() 85 uf.page.uf_args['point'].selection_win_data() 86 points = uf.page.uf_args['point'].GetValue() 87 print("Points: %s" % points) 88 self.assertEqual(points, None) 89 90 # Set a valid point in the wizard, open and close the Sequence_2D window (twice), and check that the point comes back. 91 uf.page.uf_args['point'].SetValue(str_to_gui('[[1, 2, -3.]]')) 92 uf.page.uf_args['point'].selection_win_show() 93 uf.page.uf_args['point'].selection_win_data() 94 uf.page.uf_args['point'].selection_win_show() 95 uf.page.uf_args['point'].selection_win_data() 96 points = uf.page.uf_args['point'].GetValue() 97 print("Points: %s" % points) 98 self.assertEqual(len(points), 1) 99 self.assertEqual(len(points[0]), 3) 100 self.assertEqual(points[0][0], 1.0) 101 self.assertEqual(points[0][1], 2.0) 102 self.assertEqual(points[0][2], -3.0) 103 104 # Set 2 valid points in the wizard, open and close the Sequence_2D window (twice), and check that the points come back. 105 uf.page.uf_args['point'].SetValue(str_to_gui('[[1, 2, 3], [-2, -3, -4]]')) 106 uf.page.uf_args['point'].selection_win_show() 107 uf.page.uf_args['point'].selection_win_data() 108 uf.page.uf_args['point'].selection_win_show() 109 uf.page.uf_args['point'].selection_win_data() 110 points = uf.page.uf_args['point'].GetValue() 111 print("Points: %s" % points) 112 self.assertEqual(len(points), 2) 113 self.assertEqual(len(points[0]), 3) 114 self.assertEqual(len(points[1]), 3) 115 self.assertEqual(points[0][0], 1.0) 116 self.assertEqual(points[0][1], 2.0) 117 self.assertEqual(points[0][2], 3.0) 118 self.assertEqual(points[1][0], -2.0) 119 self.assertEqual(points[1][1], -3.0) 120 self.assertEqual(points[1][2], -4.0) 121 122 # Set the points to a number of invalid values, checking that they are ignored. 123 for val in ['2', 'die', '[1, 2, 3]', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: 124 uf.page.uf_args['point'].SetValue(str_to_gui(val)) 125 uf.page.uf_args['point'].selection_win_show() 126 uf.page.uf_args['point'].selection_win_data() 127 points = uf.page.uf_args['point'].GetValue() 128 print("Points: %s" % points) 129 self.assertEqual(points, None) 130 131 # Set the Sequence_2D elements to invalid values. 132 for val in ['x']: 133 uf.page.uf_args['point'].SetValue(str_to_gui('')) 134 uf.page.uf_args['point'].selection_win_show() 135 uf.page.uf_args['point'].sel_win.sequence.SetStringItem(index=0, col=2, label=str_to_gui(val)) 136 uf.page.uf_args['point'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) 137 uf.page.uf_args['point'].selection_win_data() 138 points = uf.page.uf_args['point'].GetValue() 139 print("Points: %s" % points) 140 self.assertEqual(len(points), 1) 141 self.assertEqual(len(points[0]), 3) 142 self.assertEqual(points[0][0], 1.0) 143 self.assertEqual(points[0][1], None) 144 self.assertEqual(points[0][2], None)
145 146
148 """Test the operation of the spectrum.read_intensities user function GUI window.""" 149 150 # Open the spectrum.read_intensities user function window. 151 uf = uf_store['spectrum.read_intensities'] 152 uf._sync = True 153 uf.create_wizard(parent=self.app.gui) 154 155 # Set the y-value of a single pos, and check. 156 uf.page.uf_args['file'].selection_win_show() 157 uf.page.uf_args['file'].sel_win.SetValue('test_file') 158 uf.page.uf_args['file'].selection_win_data() 159 file = uf.page.uf_args['file'].GetValue() 160 print("File names: %s" % file) 161 self.assert_(isinstance(file, str)) 162 self.assertEqual(file, 'test_file') 163 164 # Set the file to nothing in the wizard, open the Sequence window, close the window, and check that None comes back. 165 uf.page.uf_args['file'].SetValue(str_to_gui('')) 166 uf.page.uf_args['file'].selection_win_show() 167 uf.page.uf_args['file'].selection_win_data() 168 file = uf.page.uf_args['file'].GetValue() 169 print("File names: %s" % file) 170 self.assertEqual(file, None) 171 172 # Set a valid file list in the wizard, open and close the Sequence window (twice), and check that the file comes back. 173 uf.page.uf_args['file'].SetValue(str_to_gui("['test1', 'test2']")) 174 uf.page.uf_args['file'].selection_win_show() 175 uf.page.uf_args['file'].selection_win_data() 176 uf.page.uf_args['file'].selection_win_show() 177 uf.page.uf_args['file'].selection_win_data() 178 file = uf.page.uf_args['file'].GetValue() 179 print("File names: %s" % file) 180 self.assertEqual(len(file), 2) 181 self.assertEqual(file[0], 'test1') 182 self.assertEqual(file[1], 'test2') 183 184 # Set the file to a number of invalid values, checking that they are ignored. 185 for val in ["['1', '2', '3'", "['1'"]: 186 uf.page.uf_args['file'].SetValue(str_to_gui(val)) 187 uf.page.uf_args['file'].selection_win_show() 188 uf.page.uf_args['file'].selection_win_data() 189 file = uf.page.uf_args['file'].GetValue() 190 print("Invalid file: %s\nFile names: %s" % (val, file)) 191 self.assertEqual(file, None)
192 193
194 - def test_structure_add_atom(self):
195 """Test the operation of the structure.add_atom user function GUI window.""" 196 197 # Open the structure.add_atom user function window. 198 uf = uf_store['structure.add_atom'] 199 uf._sync = True 200 uf.create_wizard(parent=self.app.gui) 201 202 # Set the y-value of a single pos, and check. 203 uf.page.uf_args['pos'].selection_win_show() 204 uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(2)) 205 uf.page.uf_args['pos'].selection_win_data() 206 pos = uf.page.uf_args['pos'].GetValue() 207 print("Pos: %s" % pos) 208 self.assertEqual(len(pos), 3) 209 self.assertEqual(pos[0], None) 210 self.assertEqual(pos[1], 2.0) 211 self.assertEqual(pos[2], None) 212 213 # Set the pos to nothing in the wizard, open the Sequence window, close the window, and check that None comes back. 214 uf.page.uf_args['pos'].SetValue(str_to_gui('')) 215 uf.page.uf_args['pos'].selection_win_show() 216 uf.page.uf_args['pos'].selection_win_data() 217 pos = uf.page.uf_args['pos'].GetValue() 218 print("Pos: %s" % pos) 219 self.assertEqual(pos, None) 220 221 # Set a valid pos in the wizard, open and close the Sequence window (twice), and check that the pos comes back. 222 uf.page.uf_args['pos'].SetValue(str_to_gui('[1, 2, -3.]')) 223 uf.page.uf_args['pos'].selection_win_show() 224 uf.page.uf_args['pos'].selection_win_data() 225 uf.page.uf_args['pos'].selection_win_show() 226 uf.page.uf_args['pos'].selection_win_data() 227 pos = uf.page.uf_args['pos'].GetValue() 228 print("Pos: %s" % pos) 229 self.assertEqual(len(pos), 3) 230 self.assertEqual(pos[0], 1.0) 231 self.assertEqual(pos[1], 2.0) 232 self.assertEqual(pos[2], -3.0) 233 234 # Set the pos to a number of invalid values, checking that they are ignored. 235 for val in ['2', 'die', '[1, 2, 3', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: 236 uf.page.uf_args['pos'].SetValue(str_to_gui(val)) 237 uf.page.uf_args['pos'].selection_win_show() 238 uf.page.uf_args['pos'].selection_win_data() 239 pos = uf.page.uf_args['pos'].GetValue() 240 print("Invalid pos: %s\nPos: %s" % (val, pos)) 241 self.assertEqual(pos, None) 242 243 # Set the Sequence elements to invalid values. 244 for val in ['x']: 245 uf.page.uf_args['pos'].SetValue(str_to_gui('')) 246 uf.page.uf_args['pos'].selection_win_show() 247 uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(index=1, col=1, label=str_to_gui(val)) 248 uf.page.uf_args['pos'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) 249 uf.page.uf_args['pos'].selection_win_data() 250 pos = uf.page.uf_args['pos'].GetValue() 251 print("Pos: %s" % pos) 252 self.assertEqual(len(pos), 3) 253 self.assertEqual(pos[0], 1.0) 254 self.assertEqual(pos[1], None) 255 self.assertEqual(pos[2], None)
256 257
258 - def test_structure_pdb_read(self):
259 """Test the full operation of the structure.read_pdb user function GUI window.""" 260 261 # Create the data pipe. 262 self.exec_uf_pipe_create(pipe_name='PDB reading test') 263 264 # Open the structure.read_pdb user function window. 265 uf = uf_store['structure.read_pdb'] 266 uf._sync = True 267 uf.create_wizard(parent=self.app.gui) 268 269 # The PDB file to operate on. 270 file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'structures' + sep + 'trunc_ubi_pcs.pdb' 271 uf.page.SetValue('file', str_to_gui(file)) 272 273 # Set the models to read. 274 uf.page.SetValue('read_model', str_to_gui('6')) 275 uf.page.uf_args['read_model'].selection_win_show() 276 uf.page.uf_args['read_model'].sel_win.add_element(None) 277 uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(2)) 278 uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(4)) 279 uf.page.uf_args['read_model'].selection_win_data() 280 281 # Renumber the models. 282 uf.page.uf_args['set_model_num'].selection_win_show() 283 uf.page.uf_args['set_model_num'].sel_win.add_element(None) 284 uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) 285 uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(3)) 286 uf.page.uf_args['set_model_num'].selection_win_data() 287 288 # GUI data checks. 289 self.assertEqual(uf.page.uf_args['read_model'].GetValue(), [2, 4]) 290 self.assertEqual(uf.page.uf_args['set_model_num'].GetValue(), [1, 3]) 291 292 # Execute the user function. 293 uf.wizard._go_next(None) 294 295 # Check the structural data. 296 self.assert_(hasattr(cdp, 'structure')) 297 self.assert_(hasattr(cdp.structure, 'structural_data')) 298 self.assertEqual(len(cdp.structure.structural_data), 2) 299 self.assertEqual(cdp.structure.structural_data[0].num, 1) 300 self.assertEqual(cdp.structure.structural_data[1].num, 3)
301 302
303 - def test_structure_rotate(self):
304 """Test the operation of the structure.rotate user function GUI window.""" 305 306 # Create the data pipe. 307 self.exec_uf_pipe_create(pipe_name='PDB rotation test') 308 309 # Open the structure.read_pdb user function window. 310 uf = uf_store['structure.read_pdb'] 311 uf._sync = True 312 uf.create_wizard(parent=self.app.gui) 313 314 # The PDB file to operate on. 315 file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'structures' + sep + 'trunc_ubi_pcs.pdb' 316 uf.page.SetValue('file', str_to_gui(file)) 317 318 # Set the models to read. 319 uf.page.SetValue('read_model', str_to_gui('6')) 320 uf.page.uf_args['read_model'].selection_win_show() 321 uf.page.uf_args['read_model'].sel_win.add_element(None) 322 uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(2)) 323 uf.page.uf_args['read_model'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(4)) 324 uf.page.uf_args['read_model'].selection_win_data() 325 326 # Renumber the models. 327 uf.page.uf_args['set_model_num'].selection_win_show() 328 uf.page.uf_args['set_model_num'].sel_win.add_element(None) 329 uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=0, col=1, label=int_to_gui(1)) 330 uf.page.uf_args['set_model_num'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(3)) 331 uf.page.uf_args['set_model_num'].selection_win_data() 332 333 # GUI data checks. 334 self.assertEqual(uf.page.uf_args['read_model'].GetValue(), [2, 4]) 335 self.assertEqual(uf.page.uf_args['set_model_num'].GetValue(), [1, 3]) 336 337 # Execute the user function. 338 uf.wizard._go_next(None) 339 340 # Open the structure.rotate user function window. 341 uf = uf_store['structure.rotate'] 342 uf._sync = True 343 uf.create_wizard(parent=self.app.gui) 344 345 # Change the rotation matrix in the Sequence_2D window, without changing anything, then check it. 346 uf.page.uf_args['R'].selection_win_show() 347 uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(2)) 348 uf.page.uf_args['R'].selection_win_data() 349 R = uf.page.uf_args['R'].GetValue() 350 print("Rotation matrix:\n%s" % R) 351 self.assertEqual(len(R), 3) 352 self.assertEqual(len(R[0]), 3) 353 self.assertEqual(R[0][0], 1) 354 self.assertEqual(R[0][1], 0) 355 self.assertEqual(R[0][2], 0) 356 self.assertEqual(R[1][0], 0) 357 self.assertEqual(R[1][1], 2) 358 self.assertEqual(R[1][2], 0) 359 self.assertEqual(R[2][0], 0) 360 self.assertEqual(R[2][1], 0) 361 self.assertEqual(R[2][2], 1) 362 363 # Set the rotation matrix to nothing in the wizard, open the Sequence_2D window, set a value, close the window, and check what happens. 364 uf.page.uf_args['R'].SetValue(str_to_gui('')) 365 uf.page.uf_args['R'].selection_win_show() 366 uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=1, col=1, label=int_to_gui(2)) 367 uf.page.uf_args['R'].selection_win_data() 368 R = uf.page.uf_args['R'].GetValue() 369 print("Rotation matrix:\n%s" % R) 370 self.assertEqual(len(R), 3) 371 self.assertEqual(len(R[0]), 3) 372 self.assertEqual(R[0][0], None) 373 self.assertEqual(R[0][1], None) 374 self.assertEqual(R[0][2], None) 375 self.assertEqual(R[1][0], None) 376 self.assertEqual(R[1][1], 2) 377 self.assertEqual(R[1][2], None) 378 self.assertEqual(R[2][0], None) 379 self.assertEqual(R[2][1], None) 380 self.assertEqual(R[2][2], None) 381 382 # Set the rotation matrix to nothing in the wizard, open the Sequence_2D window, close the window, and check that None comes back. 383 uf.page.uf_args['R'].SetValue(str_to_gui('')) 384 uf.page.uf_args['R'].selection_win_show() 385 uf.page.uf_args['R'].selection_win_data() 386 R = uf.page.uf_args['R'].GetValue() 387 print("Rotation matrix:\n%s" % R) 388 self.assertEqual(R, None) 389 390 # Set the rotation matrix to a number of invalid values, checking that they are ignored. 391 for val in ['2', 'die', '[1, 2, 3]', '[1]', '[[1, 2, 3], 1, 2, 3], [1, 2, 3]]']: 392 uf.page.uf_args['R'].SetValue(str_to_gui(val)) 393 uf.page.uf_args['R'].selection_win_show() 394 uf.page.uf_args['R'].selection_win_data() 395 R = uf.page.uf_args['R'].GetValue() 396 print("Rotation matrix:\n%s" % R) 397 self.assertEqual(R, None) 398 399 # Set the Sequence_2D elements to invalid values. 400 for val in ['x']: 401 uf.page.uf_args['R'].SetValue(str_to_gui('')) 402 uf.page.uf_args['R'].selection_win_show() 403 uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=1, col=1, label=str_to_gui(val)) 404 uf.page.uf_args['R'].sel_win.sequence.SetStringItem(index=0, col=0, label=int_to_gui(1)) 405 uf.page.uf_args['R'].selection_win_data() 406 R = uf.page.uf_args['R'].GetValue() 407 print("Rotation matrix:\n%s" % R) 408 self.assertEqual(len(R), 3) 409 self.assertEqual(len(R[0]), 3) 410 self.assertEqual(R[0][0], 1.0) 411 self.assertEqual(R[0][1], None) 412 self.assertEqual(R[0][2], None) 413 self.assertEqual(R[1][0], None) 414 self.assertEqual(R[1][1], None) 415 self.assertEqual(R[1][2], None) 416 self.assertEqual(R[2][0], None) 417 self.assertEqual(R[2][1], None) 418 self.assertEqual(R[2][2], None) 419 420 # Check the structural data. 421 self.assert_(hasattr(cdp, 'structure')) 422 self.assert_(hasattr(cdp.structure, 'structural_data')) 423 self.assertEqual(len(cdp.structure.structural_data), 2) 424 self.assertEqual(cdp.structure.structural_data[0].num, 1) 425 self.assertEqual(cdp.structure.structural_data[1].num, 3)
426 427
428 - def test_value_set(self):
429 """Test the full operation of the value.set user function GUI window.""" 430 431 # Create the data pipe. 432 self.exec_uf_pipe_create(pipe_name='value.set user function test') 433 434 # Create a spin to add data to. 435 uf = uf_store['spin.create'] 436 uf._sync = True 437 uf.create_wizard(parent=self.app.gui) 438 uf.page.SetValue('res_num', int_to_gui(1)) 439 uf.page.SetValue('res_name', str_to_gui('Gly')) 440 uf.page.SetValue('spin_name', str_to_gui('N')) 441 uf.wizard._go_next(None) 442 443 # Open the value.set user function window. 444 uf = uf_store['value.set'] 445 uf._sync = True 446 uf.create_wizard(parent=self.app.gui) 447 uf.page.SetValue('val', float_to_gui(-0.000172)) 448 uf.page.SetValue('param', str_to_gui('csa')) 449 uf.wizard._go_next(None)
450