[Scipy-svn] r6871 - in trunk/scipy/io/matlab: . tests

scipy-svn@scip... scipy-svn@scip...
Thu Nov 11 18:57:30 CST 2010


Author: matthew.brett@gmail.com
Date: 2010-11-11 18:57:30 -0600 (Thu, 11 Nov 2010)
New Revision: 6871

Modified:
   trunk/scipy/io/matlab/mio5.py
   trunk/scipy/io/matlab/miobase.py
   trunk/scipy/io/matlab/tests/test_mio.py
Log:
TESTS - add tests for varmat_from_mat; rename warning from Paulis suggestions

Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py	2010-11-12 00:57:18 UTC (rev 6870)
+++ trunk/scipy/io/matlab/mio5.py	2010-11-12 00:57:30 UTC (rev 6871)
@@ -90,7 +90,7 @@
 
 from miobase import MatFileReader, docfiller, matdims, \
      read_dtype, arr_to_chars, arr_dtype_number, \
-     MatWriteError, MatReadError
+     MatWriteError, MatReadError, MatReadWarning
 
 # Reader object for matlab 5 format variables
 from mio5_utils import VarReader5
@@ -275,7 +275,7 @@
                               ' - replacing previous with new\n'
                               'Consider mio5.varmats_from_mat to split '
                               'file into single variable files' % name,
-                              UserWarning, stacklevel=2)
+                              MatReadWarning, stacklevel=2)
             if name == '':
                 # can only be a matlab 7 function workspace
                 name = '__function_workspace__'
@@ -806,10 +806,10 @@
         Parameters
         ----------
         mdict : mapping
-           mapping with method ``items`` return name, contents pairs
-           where ``name`` which will appeak in the matlab workspace in
-           file load, and ``contents`` is something writeable to a
-           matlab file, such as a numpy array.
+           mapping with method ``items`` returns name, contents pairs where
+           ``name`` which will appear in the matlab workspace in file load, and
+           ``contents`` is something writeable to a matlab file, such as a numpy
+           array.
         write_header : {None, True, False}
            If True, then write the matlab file header before writing the
            variables.  If None (the default) then write the file header

Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py	2010-11-12 00:57:18 UTC (rev 6870)
+++ trunk/scipy/io/matlab/miobase.py	2010-11-12 00:57:30 UTC (rev 6871)
@@ -20,6 +20,8 @@
 
 class MatWriteError(Exception): pass
 
+class MatReadWarning(UserWarning): pass
+
 doc_dict = \
     {'file_arg':
          '''file_name : string

Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py	2010-11-12 00:57:18 UTC (rev 6870)
+++ trunk/scipy/io/matlab/tests/test_mio.py	2010-11-12 00:57:30 UTC (rev 6871)
@@ -40,7 +40,7 @@
 from scipy.io.matlab.mio import find_mat_file, mat_reader_factory, \
     loadmat, savemat
 from scipy.io.matlab.mio5 import MatlabObject, MatFile5Writer, \
-      MatFile5Reader, MatlabFunction
+      MatFile5Reader, MatlabFunction, varmats_from_mat
 
 # Use future defaults to silence unwanted test warnings
 savemat_future = partial(savemat, oned_as='row')
@@ -827,5 +827,25 @@
         assert_equal(np.dtype(dts), vars['arr'].dtype)
 
 
+def test_varmats_from_mat():
+    # Make a mat file with several variables, write it, read it back
+    names_vars = (('arr', mlarr(np.arange(10))),
+                  ('mystr', mlarr('a string')),
+                  ('mynum', mlarr(10)))
+    # Dict like thing to give variables in defined order
+    class C(object):
+        def items(self): return names_vars
+    stream = BytesIO()
+    savemat_future(stream, C())
+    varmats = varmats_from_mat(stream)
+    assert_equal(len(varmats), 3)
+    for i in range(3):
+        name, var_stream = varmats[i]
+        exp_name, exp_res = names_vars[i]
+        assert_equal(name, exp_name)
+        res = loadmat(var_stream)
+        assert_array_equal(res[name], exp_res)
+
+
 if __name__ == "__main__":
     run_module_suite()



More information about the Scipy-svn mailing list