Package test_suite :: Package system_tests :: Module state
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.state

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2013 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  # Python module imports. 
 23  from copy import deepcopy 
 24  from os import sep 
 25  from tempfile import mktemp 
 26   
 27  # relax module imports. 
 28  from data_store import Relax_data_store; ds = Relax_data_store() 
 29  import dep_check 
 30  from pipe_control.interatomic import interatomic_loop 
 31  from pipe_control.pipes import VALID_TYPES, get_pipe 
 32  from pipe_control.reset import reset 
 33  from status import Status; status = Status() 
 34  from test_suite.system_tests.base_classes import SystemTestCase 
 35   
 36   
37 -class State(SystemTestCase):
38 """Class for testing the state saving and loading user functions.""" 39
40 - def __init__(self, methodName='runTest'):
41 """Skip the tests if the C modules are non-functional. 42 43 @keyword methodName: The name of the test. 44 @type methodName: str 45 """ 46 47 # Execute the base class method. 48 super(State, self).__init__(methodName) 49 50 # Missing module. 51 if not dep_check.C_module_exp_fn and methodName in ['test_write_read_pipes']: 52 # Store in the status object. 53 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
54 55
56 - def setUp(self):
57 """Common set up for these system tests.""" 58 59 # Create a temporary file name. 60 self.tmpfile = mktemp()
61 62
64 """Test the loading of a relax state with an alignment tensor with MC simulation structures.""" 65 66 # The file. 67 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'align_tensor_mc.bz2' 68 69 # Load the state. 70 self.interpreter.state.load(path) 71 72 # The data. 73 domains = ['Dy N-dom', 'Dy C-dom'] 74 rdc = { 75 "Dy N-dom" : [-6.41, -21.55], 76 "Dy C-dom" : [-21.55] 77 } 78 rdc_bc = { 79 "Dy N-dom" : [None, -20.87317257368743], 80 "Dy C-dom" : [None] 81 } 82 83 rdc_err = { 84 "Dy N-dom" : [1.0, 1.0], 85 "Dy C-dom" : [1.0] 86 } 87 88 # Check the data. 89 for domain in domains: 90 # Switch to the X-domain data pipe. 91 self.interpreter.pipe.switch(domain) 92 93 # Check the interatomic data. 94 i = 0 95 for interatom in interatomic_loop(): 96 # Check the RDC data. 97 self.assertEqual(interatom.rdc[domain], rdc[domain][i]) 98 if rdc_bc[domain][i]: 99 self.assertEqual(interatom.rdc_bc[domain], rdc_bc[domain][i]) 100 if rdc_err[domain][i]: 101 self.assertEqual(interatom.rdc_err[domain], rdc_err[domain][i]) 102 103 # Increment the index. 104 i += 1
105 106
108 """Catch U{bug #21716<https://web.archive.org/web/https://gna.org/bugs/?21716>}, the failure to save the relax state when no current data pipe is set.""" 109 110 # Create two data pipes. 111 self.interpreter.pipe.create('a', 'mf') 112 self.interpreter.pipe.create('b', 'mf') 113 114 # Delete the current data pipe. 115 self.interpreter.pipe.delete('b') 116 117 # Save the state. 118 self.interpreter.state.save(self.tmpfile, force=True)
119 120
121 - def test_state_xml(self):
122 """Test the saving, loading, and second saving and loading of the program state in XML format.""" 123 124 # Create a data pipe. 125 self.interpreter.pipe.create('test', 'mf') 126 127 # Save the state. 128 self.interpreter.state.save(self.tmpfile, force=True) 129 130 # Load the state. 131 self.interpreter.state.load(self.tmpfile, force=True) 132 133 # Save the state. 134 self.interpreter.state.save(self.tmpfile, force=True) 135 136 # Load the state. 137 self.interpreter.state.load(self.tmpfile, force=True)
138 139
140 - def test_write_read_pipes(self):
141 """Test the writing out, and re-reading of data pipes from the state file.""" 142 143 # Create a data pipe. 144 self.interpreter.pipe.create('test', 'mf') 145 146 # Reset relax. 147 reset() 148 149 # The data pipe list. 150 pipe_types = deepcopy(VALID_TYPES) 151 pipe_types.pop(pipe_types.index("frame order")) 152 153 # Create a few data pipes. 154 for i in range(len(pipe_types)): 155 self.interpreter.pipe.create('test' + repr(i), pipe_types[i]) 156 157 # Write the results. 158 self.interpreter.state.save(self.tmpfile) 159 160 # Reset relax. 161 reset() 162 163 # Re-read the results. 164 self.interpreter.state.load(self.tmpfile) 165 166 # Test the pipes. 167 for i in range(len(pipe_types)): 168 # Name. 169 name = 'test' + repr(i) 170 self.assert_(name in ds) 171 172 # Type. 173 pipe = get_pipe(name) 174 self.assertEqual(pipe.pipe_type, pipe_types[i])
175