1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  from os import sep 
 24  from tempfile import mktemp 
 25   
 26   
 27  from data import Relax_data_store; ds = Relax_data_store() 
 28  from generic_fns import pipes 
 29  from generic_fns.reset import reset 
 30  from status import Status; status = Status() 
 31  from test_suite.unit_tests.base_classes import UnitTestCase 
 32   
 33   
 35      """Base class for the tests of both the 'prompt.state' and 'generic_fns.state' modules. 
 36   
 37      This base class also contains shared unit tests. 
 38      """ 
 39   
 41          """The unpickling and restoration of the relax data storage singleton. 
 42   
 43          This tests the normal operation of the generic_fns.state.load() function. 
 44          """ 
 45   
 46           
 47          self.assertEqual(list(ds.keys()), []) 
 48          self.assertEqual(pipes.cdp_name(), None) 
 49          self.assert_(not hasattr(ds, 'y')) 
 50   
 51           
 52          self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 
 53   
 54           
 55          dp = pipes.get_pipe('orig') 
 56   
 57           
 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   
 65          """The modification of an unpickled and restored relax data storage singleton. 
 66   
 67          This tests the normal operation of the generic_fns.state.load() function. 
 68          """ 
 69   
 70           
 71          self.assertEqual(list(ds.keys()), []) 
 72          self.assertEqual(pipes.cdp_name(), None) 
 73          self.assert_(not hasattr(ds, 'y')) 
 74   
 75           
 76          self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 
 77   
 78           
 79          ds.add('new', 'jw_mapping') 
 80          cdp.z = [None, None] 
 81   
 82           
 83          dp_orig = pipes.get_pipe('orig') 
 84          dp_new = pipes.get_pipe('new') 
 85   
 86           
 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   
 95          """The resetting of an unpickled and restored relax data storage singleton. 
 96   
 97          This tests the normal operation of the generic_fns.state.load() function. 
 98          """ 
 99   
100           
101          self.assertEqual(list(ds.keys()), []) 
102          self.assertEqual(pipes.cdp_name(), None) 
103          self.assert_(not hasattr(ds, 'y')) 
104   
105           
106          self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 
107   
108           
109          reset() 
110   
111           
112          self.assertEqual(list(ds.keys()), []) 
113          self.assertEqual(pipes.cdp_name(), None) 
114          self.assert_(not hasattr(ds, 'y')) 
 115   
116   
118          """The pickling and saving of the relax data storage singleton. 
119   
120          This tests the normal operation of the generic_fns.state.save() function. 
121          """ 
122   
123           
124          ds.tmpfile = mktemp() 
125   
126           
127          ds.add(pipe_name='orig', pipe_type='mf') 
128   
129           
130          dp = pipes.get_pipe('orig') 
131   
132           
133          dp.x = 1 
134   
135           
136          ds.y = 'Hello' 
137   
138           
139          self.state.save_state(state=ds.tmpfile) 
  140