Package test_suite :: Package unit_tests :: Module state_testing_base
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests.state_testing_base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-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 os import sep 
 24  from tempfile import mktemp 
 25   
 26  # relax module imports. 
 27  from data_store import Relax_data_store; ds = Relax_data_store() 
 28  from pipe_control import pipes 
 29  from pipe_control.reset import reset 
 30  from status import Status; status = Status() 
 31  from test_suite.unit_tests.base_classes import UnitTestCase 
 32   
 33   
34 -class State_base_class(UnitTestCase):
35 """Base class for the tests of both the 'prompt.state' and 'pipe_control.state' modules. 36 37 This base class also contains shared unit tests. 38 """ 39
40 - def test_load(self):
41 """The unpickling and restoration of the relax data storage singleton. 42 43 This tests the normal operation of the pipe_control.state.load() function. 44 """ 45 46 # Test the contents of the empty singleton. 47 self.assertEqual(list(ds.keys()), []) 48 self.assertEqual(pipes.cdp_name(), None) 49 self.assert_(not hasattr(ds, 'y')) 50 51 # Load the state. 52 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 53 54 # Get the data pipe. 55 dp = pipes.get_pipe('orig') 56 57 # Test the contents of the restored singleton. 58 self.assertEqual(list(ds.keys()), ['orig']) 59 self.assertEqual(pipes.cdp_name(), 'orig') 60 self.assertEqual(dp.x, 1) 61 self.assertEqual(ds.y, 'Hello')
62 63
64 - def test_load_and_modify(self):
65 """The modification of an unpickled and restored relax data storage singleton. 66 67 This tests the normal operation of the pipe_control.state.load() function. 68 """ 69 70 # Test the contents of the empty singleton. 71 self.assertEqual(list(ds.keys()), []) 72 self.assertEqual(pipes.cdp_name(), None) 73 self.assert_(not hasattr(ds, 'y')) 74 75 # Load the state. 76 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 77 78 # Add a new data pipe and some data to it. 79 ds.add('new', 'jw_mapping') 80 cdp.z = [None, None] 81 82 # Get the data pipes. 83 dp_orig = pipes.get_pipe('orig') 84 dp_new = pipes.get_pipe('new') 85 86 # Test the contents of the restored singleton (with subsequent data added). 87 self.assertEqual(list(ds.keys()).sort(), ['orig', 'new'].sort()) 88 self.assertEqual(pipes.cdp_name(), 'new') 89 self.assertEqual(dp_orig.x, 1) 90 self.assertEqual(ds.y, 'Hello') 91 self.assertEqual(dp_new.z, [None, None])
92 93
94 - def test_load_and_reset(self):
95 """The resetting of an unpickled and restored relax data storage singleton. 96 97 This tests the normal operation of the pipe_control.state.load() function. 98 """ 99 100 # Test the contents of the empty singleton. 101 self.assertEqual(list(ds.keys()), []) 102 self.assertEqual(pipes.cdp_name(), None) 103 self.assert_(not hasattr(ds, 'y')) 104 105 # Load the state. 106 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 107 108 # Reset relax. 109 reset() 110 111 # Test that there are no contents in the reset singleton. 112 self.assertEqual(list(ds.keys()), []) 113 self.assertEqual(pipes.cdp_name(), None) 114 self.assert_(not hasattr(ds, 'y'))
115 116
117 - def test_save(self):
118 """The pickling and saving of the relax data storage singleton. 119 120 This tests the normal operation of the pipe_control.state.save() function. 121 """ 122 123 # Create a temporary file descriptor. 124 ds.tmpfile = mktemp() 125 126 # Add a data pipe to the data store. 127 ds.add(pipe_name='orig', pipe_type='mf') 128 129 # Get the data pipe. 130 dp = pipes.get_pipe('orig') 131 132 # Add a single object to the 'orig' data pipe. 133 dp.x = 1 134 135 # Add a single object to the storage object. 136 ds.y = 'Hello' 137 138 # Save the state. 139 self.state.save_state(state=ds.tmpfile)
140