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

Source Code for Module test_suite.gui_tests.base_classes

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-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 docstring. 
 23  """Base classes for the GUI tests.""" 
 24   
 25  # Python module imports. 
 26  from math import pi    # This is needed for relax scripts as pi is located in the relax prompt namespace. 
 27  from os import sep 
 28  from tempfile import mktemp, mkdtemp 
 29  from unittest import TestCase 
 30  import wx 
 31   
 32  # relax module imports. 
 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   
44 -class GuiTestCase(TestCase):
45 """The GUI test base class.""" 46
47 - def __init__(self, methodName=None):
48 """Set up the test case class for the system tests.""" 49 50 # A string used for classifying skipped tests. 51 if not hasattr(self, '_skip_type'): 52 self._skip_type = 'gui' 53 54 # Execute the TestCase __init__ method. 55 super(GuiTestCase, self).__init__(methodName)
56 57
58 - def _execute_uf(self, *args, **kargs):
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 # Checks. 66 if 'uf_name' not in kargs: 67 raise RelaxError("The user function name argument 'uf_name' has not been supplied.") 68 69 # Process the user function name. 70 uf_name = kargs.pop('uf_name') 71 72 # Get the user function data object. 73 uf_data = uf_info.get_uf(uf_name) 74 75 # Convert the args into keyword args. 76 for i in range(len(args)): 77 # The keyword name for this arg. 78 name = uf_data.kargs[i]['name'] 79 80 # Check. 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 # Set the keyword arg. 85 kargs[name] = args[i] 86 87 # Add the keyword args not supplied, using the default value. 88 for i in range(len(uf_data.kargs)): 89 # Alias. 90 arg = uf_data.kargs[i] 91 92 # Already set. 93 if arg['name'] in kargs: 94 continue 95 96 # Set the default. 97 kargs[arg['name']] = arg['default'] 98 99 # Merge the file and directory args, as needed. 100 for i in range(len(uf_data.kargs)): 101 # Alias. 102 arg = uf_data.kargs[i] 103 104 # File selection and associated directory arg. 105 if arg['arg_type'] == 'dir' and arg['name'] in kargs: 106 # Find the associated file selection arg name. 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 # Prepend the directory to the file, if needed and supplied. 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 # Remove the directory argument. 116 kargs.pop(arg['name']) 117 118 # The user function object. 119 uf = uf_store[uf_name] 120 121 # Force synchronous operation of the user functions. 122 status.gui_uf_force_sync = True 123 124 # Call the GUI user function object with all keyword args, but do not execute the wizard. 125 uf(wx_wizard_run=False, **kargs) 126 127 # Execute the user function, by mimicking a click on 'ok'. 128 uf.wizard._ok() 129 130 # Restore the synchronous or asynchronous operation of the user functions so the GUI can return to normal. 131 status.gui_uf_force_sync = False
132 133
134 - def check_exceptions(self):
135 """Check that no exception has occurred.""" 136 137 # Check. 138 try: 139 # Get the exception from the queue. 140 index, exc = status.exception_queue.get(block=False) 141 142 # Print out. 143 print("Exception found, failing the test with an AssertionError:\n") 144 145 # Fail. 146 self.fail() 147 148 # No exception. 149 except queue.Empty: 150 pass
151 152
153 - def script_exec(self, script):
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 # The namespace to pass into the script execution environment. 161 space = locals() 162 163 # Place some objects in the local namespace. 164 space.update({'pi': pi}) 165 166 # Execute the script. 167 exec_script(script, space)
168 169
170 - def setUp(self):
171 """Set up for all the functional tests.""" 172 173 # Create a temporary file for the tests that need it. 174 ds.tmpfile = mktemp() 175 176 # Create a temporary directory for the results. 177 ds.tmpdir = mkdtemp() 178 179 # Get the wx app. 180 self.app = wx.GetApp()
181 182
183 - def tearDown(self):
184 """Default tearDown operation - delete temp directories and files and reset relax.""" 185 186 # Flush all wx events prior to the clean up operations of this method. This prevents these events from occurring after the GUI elements have been deleted. 187 wx.Yield() 188 189 # Remove the temporary directory and variable. 190 deletion(obj=ds, name='tmpdir', dir=True) 191 deletion(obj=self, name='tmpdir', dir=True) 192 193 # Remove temporary file and variable. 194 deletion(obj=ds, name='tmpfile', dir=False) 195 deletion(obj=self, name='tmpfile', dir=False) 196 197 # Reset relax. 198 reset() 199 200 # Flush all wx events again to allow the reset event to propagate throughout the GUI and the execution lock to be released before the next test starts. 201 wx.Yield()
202