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
107 - def test_state_xml(self):
108 """Test the saving, loading, and second saving and loading of the program state in XML format.""" 109 110 # Create a data pipe. 111 self.interpreter.pipe.create('test', 'mf') 112 113 # Save the state. 114 self.interpreter.state.save(self.tmpfile, force=True) 115 116 # Load the state. 117 self.interpreter.state.load(self.tmpfile, force=True) 118 119 # Save the state. 120 self.interpreter.state.save(self.tmpfile, force=True) 121 122 # Load the state. 123 self.interpreter.state.load(self.tmpfile, force=True)
124 125
126 - def test_write_read_pipes(self):
127 """Test the writing out, and re-reading of data pipes from the state file.""" 128 129 # Create a data pipe. 130 self.interpreter.pipe.create('test', 'mf') 131 132 # Reset relax. 133 reset() 134 135 # The data pipe list. 136 pipe_types = deepcopy(VALID_TYPES) 137 pipe_types.pop(pipe_types.index("frame order")) 138 139 # Create a few data pipes. 140 for i in range(len(pipe_types)): 141 self.interpreter.pipe.create('test' + repr(i), pipe_types[i]) 142 143 # Write the results. 144 self.interpreter.state.save(self.tmpfile) 145 146 # Reset relax. 147 reset() 148 149 # Re-read the results. 150 self.interpreter.state.load(self.tmpfile) 151 152 # Test the pipes. 153 for i in range(len(pipe_types)): 154 # Name. 155 name = 'test' + repr(i) 156 self.assert_(name in ds) 157 158 # Type. 159 pipe = get_pipe(name) 160 self.assertEqual(pipe.pipe_type, pipe_types[i])
161