mailr26905 - in /branches/space_mapping_refactor: ./ lib/arg_check.py test_suite/system_tests/state.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on December 02, 2014 - 21:57:
Author: bugman
Date: Tue Dec  2 21:57:15 2014
New Revision: 26905

URL: http://svn.gna.org/viewcvs/relax?rev=26905&view=rev
Log:
Merged revisions 26901-26902 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r26901 | bugman | 2014-12-02 21:39:10 +0100 (Tue, 02 Dec 2014) | 9 lines
  
  Created the State.test_bug_23017_ieee_754_multidim_numpy_arrays system test.
  
  This is to catch bug #23017 (https://gna.org/bugs/?23017), the 
multidimensional numpy arrays are not
  being stored as IEEE 754 arrays in the XML state and results files.
  
  This test checks a rank-2 float64 numpy array stored in the current data 
pipe against what the IEEE
  754 int list should be for it.
........
  r26902 | bugman | 2014-12-02 21:42:14 +0100 (Tue, 02 Dec 2014) | 9 lines
  
  Simple fix for bug #23017 (https://gna.org/bugs/?23017).
  
  This is the multidimensional numpy arrays are not being stored as IEEE 754 
arrays in the XML state
  and results files.  The problem was a relatively recent regression caused 
by a change to the
  is_float_matrix() function of the lib.arg_check module.  It was simply that 
the default dims keyword
  argument value was changed from None to (3, 3).  Therefore any call to the 
function without
  supplying the dims argument would fail if the matrix was not of the (3, 3) 
shape.
........

Modified:
    branches/space_mapping_refactor/   (props changed)
    branches/space_mapping_refactor/lib/arg_check.py
    branches/space_mapping_refactor/test_suite/system_tests/state.py

Propchange: branches/space_mapping_refactor/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Dec  2 21:57:15 2014
@@ -1 +1 @@
-/trunk:1-26871,26874-26885
+/trunk:1-26904

Modified: branches/space_mapping_refactor/lib/arg_check.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/space_mapping_refactor/lib/arg_check.py?rev=26905&r1=26904&r2=26905&view=diff
==============================================================================
--- branches/space_mapping_refactor/lib/arg_check.py    (original)
+++ branches/space_mapping_refactor/lib/arg_check.py    Tue Dec  2 21:57:15 
2014
@@ -150,7 +150,7 @@
     return True
 
 
-def is_float_matrix(arg, name=None, dim=(3, 3), can_be_none=False, 
none_elements=False, raise_error=True):
+def is_float_matrix(arg, name=None, dim=None, can_be_none=False, 
none_elements=False, raise_error=True):
     """Test if the argument is a matrix of floats.
 
     @param arg:                         The argument.

Modified: branches/space_mapping_refactor/test_suite/system_tests/state.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/space_mapping_refactor/test_suite/system_tests/state.py?rev=26905&r1=26904&r2=26905&view=diff
==============================================================================
--- branches/space_mapping_refactor/test_suite/system_tests/state.py    
(original)
+++ branches/space_mapping_refactor/test_suite/system_tests/state.py    Tue 
Dec  2 21:57:15 2014
@@ -21,7 +21,9 @@
 
 # Python module imports.
 from copy import deepcopy
+from numpy import array, float64
 from os import sep
+from re import search
 from tempfile import mktemp
 
 # relax module imports.
@@ -51,6 +53,86 @@
         if not dep_check.C_module_exp_fn and methodName in 
['test_write_read_pipes']:
             # Store in the status object. 
             status.skipped_tests.append([methodName, 'Relax curve-fitting C 
module', self._skip_type])
+
+
+    def get_ieee_754(self, lines=None):
+        """Find and convert the IEEE 754 int list from the list of text 
lines.
+
+        @keyword lines: The lines of XML text to extract the IEEE 754 array 
from.
+        @type lines:    list of str
+        @return:        The IEEE 754 array, if it exists.
+        @rtype:         list of int
+        """
+
+        # Loop over the lines, finding the IEEE 754 lines.
+        ieee_754 = ""
+        in_tag = False
+        for line in lines:
+            # The tag start line, so switch the flag.
+            if search("<ieee_754", line):
+                in_tag = True
+
+            # The tag  end line, so store the line and switch the flag.
+            if search("</ieee_754", line):
+                ieee_754 += line
+                in_tag = False
+
+            # Store the line.
+            if in_tag:
+                ieee_754 += line
+
+        # Strip the tags and newlines.
+        ieee_754 = ieee_754.replace('<ieee_754_byte_array>', '')
+        ieee_754 = ieee_754.replace('</ieee_754_byte_array>', '')
+        ieee_754 = ieee_754.replace('\n', '')
+
+        # Nothing left.
+        if ieee_754 == '':
+            return None
+
+        # Convert the remaining text to an int list.
+        ieee_754 = eval(ieee_754)
+
+        # Return the array.
+        return ieee_754
+
+
+
+    def get_xml_tag(self, file=None, name=None):
+        """Extract the text lines for the given XML tag.
+
+        @keyword file:  The file name top open.
+        @type file:     str
+        @keyword name:  The XML tag name to isolate.
+        @type name:     str
+        @return:        The list of lines corresponding to the XML tag.
+        @rtype:         list of str
+        """
+
+        # Read the contents of the file.
+        file = open(file)
+        lines = file.readlines()
+        file.close()
+
+        # Loop over the lines, finding all corresponding tags.
+        tag_lines = []
+        in_tag = False
+        for line in lines:
+            # The tag start line, so switch the flag.
+            if search("<%s "%name, line):
+                in_tag = True
+
+            # The tag  end line, so store the line and switch the flag.
+            if search("</%s>"%name, line):
+                tag_lines.append(line)
+                in_tag = False
+
+            # Store the line.
+            if in_tag:
+                tag_lines.append(line)
+
+        # Return the lines.
+        return tag_lines
 
 
     def setUp(self):
@@ -118,6 +200,28 @@
         self.interpreter.state.save(self.tmpfile, force=True)
 
 
+    def test_bug_23017_ieee_754_multidim_numpy_arrays(self):
+        """Test catching U{bug #23017<https://gna.org/bugs/?23017>}, the 
multidimensional numpy arrays are not being stored as IEEE 754 arrays in the 
XML state and results files."""
+
+        # Create a data pipe.
+        self.interpreter.pipe.create('test', 'mf')
+
+        # The numpy structure.
+        cdp.test = array([[1, 2, 3], [4, 5, 6]], float64)
+
+        # Save the state.
+        self.interpreter.state.save(self.tmpfile, compress_type=0, 
force=True)
+
+        # Get the tag lines.
+        lines = self.get_xml_tag(file=self.tmpfile, name='test')
+
+        # Extract the IEEE 754 array as an int list.
+        ieee_754 = self.get_ieee_754(lines=lines)
+
+        # Check.
+        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]]])
+
+
     def test_state_xml(self):
         """Test the saving, loading, and second saving and loading of the 
program state in XML format."""
 




Related Messages


Powered by MHonArc, Updated Wed Dec 03 09:00:04 2014