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-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Base classes for the GUI tests.""" 
 25   
 26  # Python module imports. 
 27  import Queue 
 28  from shutil import rmtree 
 29  from tempfile import mkdtemp 
 30  from unittest import TestCase 
 31  import wx 
 32   
 33  # Dependency checks. 
 34  import dep_check 
 35   
 36  # relax module imports. 
 37  from data import Relax_data_store; ds = Relax_data_store() 
 38  from data.gui import Gui 
 39  from generic_fns.reset import reset 
 40  from status import Status; status = Status() 
 41   
 42  # relax GUI module imports. 
 43  from gui.interpreter import Interpreter; interpreter = Interpreter() 
 44   
 45   
46 -class GuiTestCase(TestCase):
47 """The GUI specific test case.""" 48
49 - def __init__(self, methodName=None):
50 """Set up the test case class for the system tests.""" 51 52 # Execute the TestCase __init__ method. 53 super(GuiTestCase, self).__init__(methodName) 54 55 # Get the wx app, if the test suite is launched from the gui. 56 self.app = wx.GetApp() 57 58 # Flag for the GUI. 59 self._gui_launch = False 60 if self.app != None: 61 self._gui_launch = True
62 63
64 - def check_exceptions(self):
65 """Check that no exception has occurred.""" 66 67 # Check. 68 try: 69 # Get the exception from the queue. 70 index, exc = status.exception_queue.get(block=False) 71 72 # Fail. 73 self.fail() 74 75 # No exception. 76 except Queue.Empty: 77 pass
78 79
80 - def execute_uf(self, page=None, **kargs):
81 """Execute the given user function. 82 83 @keyword page: The user function page. 84 @type page: Wizard page 85 """ 86 87 # Create and store a wizard instance to be used in all user function pages (if needed). 88 if not hasattr(self, '_wizard'): 89 self._wizard = Wiz_window(self.app.gui) 90 91 # Initialise the page (adding it to the wizard). 92 uf_page = page(self._wizard) 93 94 # Set all the values. 95 for key in kargs: 96 uf_page.SetValue(key=key, value=kargs[key]) 97 98 # Execute the user function. 99 uf_page.on_execute() 100 101 # Flush the interpreter to force synchronous user functions operation. 102 interpreter.flush()
103 104
105 - def setUp(self):
106 """Set up for all the functional tests.""" 107 108 # Create a temporary directory for the results. 109 ds.tmpdir = mkdtemp() 110 111 # Start the GUI if not launched from the GUI. 112 if not self._gui_launch: 113 self.app = wx.App(redirect=False) 114 115 # relax GUI imports (here to prevent a circular import from the test suite in the GUI). 116 if dep_check.wx_module: 117 from gui.relax_gui import Main 118 119 # Build the GUI. 120 self.app.gui = Main(parent=None, id=-1, title="")
121 122
123 - def tearDown(self):
124 """Default tearDown operation - delete temp directories and files and reset relax.""" 125 126 # Remove the temporary directories. 127 if hasattr(ds, 'tmpdir'): 128 # Delete the directory. 129 rmtree(ds.tmpdir) 130 131 # Remove the variable. 132 del ds.tmpdir 133 134 # Remove the temporary directories. 135 if hasattr(self, 'tmpdir'): 136 # Delete the directory. 137 rmtree(self.tmpdir) 138 139 # Remove the variable. 140 del self.tmpdir 141 142 # Remove temporary files. 143 if hasattr(ds, 'tmpfile'): 144 # Delete the file. 145 delete(ds.tmpfile, fail=False) 146 147 # Remove the variable. 148 del ds.tmpfile 149 150 # Remove temporary files. 151 if hasattr(self, 'tmpfile'): 152 # Delete the file. 153 delete(self.tmpfile, fail=False) 154 155 # Remove the variable. 156 del self.tmpfile 157 158 # Delete all the GUI analysis tabs. 159 self.app.gui.analysis.delete_all() 160 161 # Reset relax. 162 reset() 163 164 # Reset the observers. 165 status._setup_observers() 166 167 # Destroy some GUI windows, if open. 168 windows = ['pipe_editor', 'relax_prompt', 'results_viewer', 'spin_viewer'] 169 for window in windows: 170 if hasattr(self.app.gui, window): 171 # Get the object. 172 win_obj = getattr(self.app.gui, window) 173 174 # Destroy the wxWidget part. 175 win_obj.Destroy() 176 177 # Destroy the Python object part. 178 delattr(self.app.gui, window) 179 180 # Destroy the GUI. 181 if not self._gui_launch and hasattr(self.app, 'gui'): 182 self.app.gui.Destroy() 183 184 # Recreate the GUI data object. 185 ds.relax_gui = Gui() 186 187 # Delete any wizard objects. 188 if hasattr(self, '_wizard'): 189 del self._wizard 190 191 # Flush all wx events to make sure the GUI is ready for the next test. 192 wx.Yield()
193