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