1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 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   
 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           
 50          super(State, self).__init__(methodName) 
 51   
 52           
 53          if not dep_check.C_module_exp_fn and methodName in ['test_write_read_pipes']: 
 54               
 55              status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 
  56   
 57   
 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           
 68          ieee_754 = "" 
 69          in_tag = False 
 70          for line in lines: 
 71               
 72              if search("<ieee_754", line): 
 73                  in_tag = True 
 74   
 75               
 76              if search("</ieee_754", line): 
 77                  ieee_754 += line 
 78                  in_tag = False 
 79   
 80               
 81              if in_tag: 
 82                  ieee_754 += line 
 83   
 84           
 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           
 90          if ieee_754 == '': 
 91              return None 
 92   
 93           
 94          ieee_754 = eval(ieee_754) 
 95   
 96           
 97          return ieee_754 
  98   
 99   
100   
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           
113          file = open(file) 
114          lines = file.readlines() 
115          file.close() 
116   
117           
118          tag_lines = [] 
119          in_tag = False 
120          for line in lines: 
121               
122              if search("<%s "%name, line): 
123                  in_tag = True 
124   
125               
126              if search("</%s>"%name, line): 
127                  tag_lines.append(line) 
128                  in_tag = False 
129   
130               
131              if in_tag: 
132                  tag_lines.append(line) 
133   
134           
135          return tag_lines 
 136   
137   
139          """Common set up for these system tests.""" 
140   
141           
142          self.tmpfile = mktemp() 
 143   
144   
146          """Test the loading of a relax state with an alignment tensor with MC simulation structures.""" 
147   
148           
149          path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'align_tensor_mc.bz2' 
150   
151           
152          self.interpreter.state.load(path) 
153   
154           
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           
171          for domain in domains: 
172               
173              self.interpreter.pipe.switch(domain) 
174   
175               
176              i = 0 
177              for interatom in interatomic_loop(): 
178                   
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                   
186                  i += 1 
 187   
188   
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           
207          self.interpreter.pipe.create('test', 'mf') 
208   
209           
210          cdp.test = array([[1, 2, 3], [4, 5, 6]], float64) 
211   
212           
213          self.interpreter.state.save(self.tmpfile, compress_type=0, force=True) 
214   
215           
216          lines = self.get_xml_tag(file=self.tmpfile, name='test') 
217   
218           
219          ieee_754 = self.get_ieee_754(lines=lines) 
220   
221           
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   
242   
243   
245          """Test the writing out, and re-reading of data pipes from the state file.""" 
246   
247           
248          self.interpreter.pipe.create('test', 'mf') 
249   
250           
251          reset() 
252   
253           
254          pipe_types = deepcopy(VALID_TYPES) 
255          pipe_types.pop(pipe_types.index("frame order")) 
256   
257           
258          for i in range(len(pipe_types)): 
259              self.interpreter.pipe.create('test' + repr(i), pipe_types[i]) 
260   
261           
262          self.interpreter.state.save(self.tmpfile) 
263   
264           
265          reset() 
266   
267           
268          self.interpreter.state.load(self.tmpfile) 
269   
270           
271          for i in range(len(pipe_types)): 
272               
273              name = 'test' + repr(i) 
274              self.assert_(name in ds) 
275   
276               
277              pipe = get_pipe(name) 
278              self.assertEqual(pipe.pipe_type, pipe_types[i]) 
  279