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