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-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  # Python module imports. 
 23  from copy import deepcopy 
 24  from numpy import array, float64 
 25  from os import sep 
 26  from re import search 
 27  from tempfile import mktemp 
 28   
 29  # relax module imports. 
 30  from data_store import Relax_data_store; ds = Relax_data_store() 
 31  import dep_check 
 32  from pipe_control.interatomic import interatomic_loop 
 33  from pipe_control.pipes import VALID_TYPES, get_pipe 
 34  from pipe_control.reset import reset 
 35  from status import Status; status = Status() 
 36  from test_suite.system_tests.base_classes import SystemTestCase 
 37   
 38   
39 -class State(SystemTestCase):
40 """Class for testing the state saving and loading user functions.""" 41
42 - def __init__(self, methodName='runTest'):
43 """Skip the tests if the C modules are non-functional. 44 45 @keyword methodName: The name of the test. 46 @type methodName: str 47 """ 48 49 # Execute the base class method. 50 super(State, self).__init__(methodName) 51 52 # Missing module. 53 if not dep_check.C_module_exp_fn and methodName in ['test_write_read_pipes']: 54 # Store in the status object. 55 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
56 57
58 - def get_ieee_754(self, lines=None):
59 """Find and convert the IEEE 754 int list from the list of text lines. 60 61 @keyword lines: The lines of XML text to extract the IEEE 754 array from. 62 @type lines: list of str 63 @return: The IEEE 754 array, if it exists. 64 @rtype: list of int 65 """ 66 67 # Loop over the lines, finding the IEEE 754 lines. 68 ieee_754 = "" 69 in_tag = False 70 for line in lines: 71 # The tag start line, so switch the flag. 72 if search("<ieee_754", line): 73 in_tag = True 74 75 # The tag end line, so store the line and switch the flag. 76 if search("</ieee_754", line): 77 ieee_754 += line 78 in_tag = False 79 80 # Store the line. 81 if in_tag: 82 ieee_754 += line 83 84 # Strip the tags and newlines. 85 ieee_754 = ieee_754.replace('<ieee_754_byte_array>', '') 86 ieee_754 = ieee_754.replace('</ieee_754_byte_array>', '') 87 ieee_754 = ieee_754.replace('\n', '') 88 89 # Nothing left. 90 if ieee_754 == '': 91 return None 92 93 # Convert the remaining text to an int list. 94 ieee_754 = eval(ieee_754) 95 96 # Return the array. 97 return ieee_754
98 99 100
101 - def get_xml_tag(self, file=None, name=None):
102 """Extract the text lines for the given XML tag. 103 104 @keyword file: The file name top open. 105 @type file: str 106 @keyword name: The XML tag name to isolate. 107 @type name: str 108 @return: The list of lines corresponding to the XML tag. 109 @rtype: list of str 110 """ 111 112 # Read the contents of the file. 113 file = open(file) 114 lines = file.readlines() 115 file.close() 116 117 # Loop over the lines, finding all corresponding tags. 118 tag_lines = [] 119 in_tag = False 120 for line in lines: 121 # The tag start line, so switch the flag. 122 if search("<%s "%name, line): 123 in_tag = True 124 125 # The tag end line, so store the line and switch the flag. 126 if search("</%s>"%name, line): 127 tag_lines.append(line) 128 in_tag = False 129 130 # Store the line. 131 if in_tag: 132 tag_lines.append(line) 133 134 # Return the lines. 135 return tag_lines
136 137
138 - def setUp(self):
139 """Common set up for these system tests.""" 140 141 # Create a temporary file name. 142 self.tmpfile = mktemp()
143 144
146 """Test the loading of a relax state with an alignment tensor with MC simulation structures.""" 147 148 # The file. 149 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'align_tensor_mc.bz2' 150 151 # Load the state. 152 self.interpreter.state.load(path) 153 154 # The data. 155 domains = ['Dy N-dom', 'Dy C-dom'] 156 rdc = { 157 "Dy N-dom" : [-6.41, -21.55], 158 "Dy C-dom" : [-21.55] 159 } 160 rdc_bc = { 161 "Dy N-dom" : [None, -20.87317257368743], 162 "Dy C-dom" : [None] 163 } 164 165 rdc_err = { 166 "Dy N-dom" : [1.0, 1.0], 167 "Dy C-dom" : [1.0] 168 } 169 170 # Check the data. 171 for domain in domains: 172 # Switch to the X-domain data pipe. 173 self.interpreter.pipe.switch(domain) 174 175 # Check the interatomic data. 176 i = 0 177 for interatom in interatomic_loop(): 178 # Check the RDC data. 179 self.assertEqual(interatom.rdc[domain], rdc[domain][i]) 180 if rdc_bc[domain][i]: 181 self.assertEqual(interatom.rdc_bc[domain], rdc_bc[domain][i]) 182 if rdc_err[domain][i]: 183 self.assertEqual(interatom.rdc_err[domain], rdc_err[domain][i]) 184 185 # Increment the index. 186 i += 1
187 188
190 """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.""" 191 192 # Create two data pipes. 193 self.interpreter.pipe.create('a', 'mf') 194 self.interpreter.pipe.create('b', 'mf') 195 196 # Delete the current data pipe. 197 self.interpreter.pipe.delete('b') 198 199 # Save the state. 200 self.interpreter.state.save(self.tmpfile, force=True)
201 202
204 """Test catching U{bug #23017<https://web.archive.org/web/https://gna.org/bugs/?23017>}, the multidimensional numpy arrays are not being stored as IEEE 754 arrays in the XML state and results files.""" 205 206 # Create a data pipe. 207 self.interpreter.pipe.create('test', 'mf') 208 209 # The numpy structure. 210 cdp.test = array([[1, 2, 3], [4, 5, 6]], float64) 211 212 # Save the state. 213 self.interpreter.state.save(self.tmpfile, compress_type=0, force=True) 214 215 # Get the tag lines. 216 lines = self.get_xml_tag(file=self.tmpfile, name='test') 217 218 # Extract the IEEE 754 array as an int list. 219 ieee_754 = self.get_ieee_754(lines=lines) 220 221 # Check. 222 self.assertEqual(ieee_754, [[[0, 0, 0, 0, 0, 0, 240, 63], [0, 0, 0, 0, 0, 0, 0, 64], [0, 0, 0, 0, 0, 0, 8, 64]], [[0, 0, 0, 0, 0, 0, 16, 64], [0, 0, 0, 0, 0, 0, 20, 64], [0, 0, 0, 0, 0, 0, 24, 64]]])
223 224
225 - def test_state_xml(self):
226 """Test the saving, loading, and second saving and loading of the program state in XML format.""" 227 228 # Create a data pipe. 229 self.interpreter.pipe.create('test', 'mf') 230 231 # Save the state. 232 self.interpreter.state.save(self.tmpfile, force=True) 233 234 # Load the state. 235 self.interpreter.state.load(self.tmpfile, force=True) 236 237 # Save the state. 238 self.interpreter.state.save(self.tmpfile, force=True) 239 240 # Load the state. 241 self.interpreter.state.load(self.tmpfile, force=True)
242 243
244 - def test_write_read_pipes(self):
245 """Test the writing out, and re-reading of data pipes from the state file.""" 246 247 # Create a data pipe. 248 self.interpreter.pipe.create('test', 'mf') 249 250 # Reset relax. 251 reset() 252 253 # The data pipe list. 254 pipe_types = deepcopy(VALID_TYPES) 255 pipe_types.pop(pipe_types.index("frame order")) 256 257 # Create a few data pipes. 258 for i in range(len(pipe_types)): 259 self.interpreter.pipe.create('test' + repr(i), pipe_types[i]) 260 261 # Write the results. 262 self.interpreter.state.save(self.tmpfile) 263 264 # Reset relax. 265 reset() 266 267 # Re-read the results. 268 self.interpreter.state.load(self.tmpfile) 269 270 # Test the pipes. 271 for i in range(len(pipe_types)): 272 # Name. 273 name = 'test' + repr(i) 274 self.assert_(name in ds) 275 276 # Type. 277 pipe = get_pipe(name) 278 self.assertEqual(pipe.pipe_type, pipe_types[i])
279