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

scipy-svn@scip... scipy-svn@scip...
Sun Nov 9 00:39:29 CST 2008


Author: matthew.brett@gmail.com
Date: 2008-11-09 00:39:26 -0600 (Sun, 09 Nov 2008)
New Revision: 5030

Modified:
   trunk/scipy/io/matlab/mio.py
   trunk/scipy/io/matlab/mio5.py
   trunk/scipy/io/matlab/miobase.py
   trunk/scipy/io/matlab/tests/test_mio.py
Log:
Added extra warnings for future behavior change, pulled out try, finally incompatible with 2.4

Modified: trunk/scipy/io/matlab/mio.py
===================================================================
--- trunk/scipy/io/matlab/mio.py	2008-11-09 05:32:46 UTC (rev 5029)
+++ trunk/scipy/io/matlab/mio.py	2008-11-09 06:39:26 UTC (rev 5030)
@@ -22,6 +22,9 @@
         file name for mat file
     %(append_arg)s
     '''
+    warnings.warn('Searching for mat files on python system path will be ' +
+                  'removed in future versions of scipy',
+                   FutureWarning, stacklevel=2)
     if appendmat and file_name[-4:] == ".mat":
         file_name = file_name[:-4]
     if os.sep in file_name:
@@ -55,10 +58,13 @@
     %(struct_arg)s
     """
     if isinstance(file_name, basestring):
-        full_name = find_mat_file(file_name, appendmat)
-        if full_name is None:
-            raise IOError, "%s not found on the path." % file_name
-        byte_stream = open(full_name, 'rb')
+        try:
+            byte_stream = open(file_name, 'rb')
+        except IOError:
+            full_name = find_mat_file(file_name, appendmat)
+            if full_name is None:
+                raise IOError, "%s not found on the path." % file_name
+            byte_stream = open(full_name, 'rb')
     else:
         try:
             file_name.read(0)
@@ -110,7 +116,7 @@
     return mdict
 
 @filldoc
-def savemat(file_name, mdict, appendmat=True, format='4'):
+def savemat(file_name, mdict, appendmat=True, format=None):
     """Save a dictionary of names and arrays into the MATLAB-style .mat file.
 
     This saves the arrayobjects in the given dictionary to a matlab
@@ -126,6 +132,11 @@
         '4' for matlab 4 mat files, '5' for matlab 5 (up to matlab
         7.2)
     """
+    if format is None:
+        warnings.warn(
+            "Using default format '4'. Default will change to '5' in future versions of scipy",
+            FutureWarning, stacklevel=2)
+        format = '4'
     file_is_string = isinstance(file_name, basestring)
     if file_is_string:
         if appendmat and file_name[-4:] != ".mat":

Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py	2008-11-09 05:32:46 UTC (rev 5029)
+++ trunk/scipy/io/matlab/mio5.py	2008-11-09 06:39:26 UTC (rev 5030)
@@ -596,7 +596,7 @@
         if struct_as_record is None:
             warnings.warn("Using struct_as_record default value (False)" +
                           " This will change to True in future versions", 
-                          DeprecationWarning, stacklevel=2)
+                          FutureWarning, stacklevel=2)
             struct_as_record = False
         self.codecs = {}
         # Missing inputs to array reader set later (processor func

Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py	2008-11-09 05:32:46 UTC (rev 5029)
+++ trunk/scipy/io/matlab/miobase.py	2008-11-09 06:39:26 UTC (rev 5030)
@@ -59,7 +59,7 @@
 	matlab files.  In a future version of scipy, we will change
 	the default setting to True, and following versions may remove
 	this flag entirely.  For now, we set the default to False, for
-	backwards compatibility, but issue a deprecation warning.
+	backwards compatibility, but issue a warning.
 	Note that non-record arrays cannot be exported via savemat.''',
     'matstream_arg':
     '''mat_stream : file-like

Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py	2008-11-09 05:32:46 UTC (rev 5029)
+++ trunk/scipy/io/matlab/tests/test_mio.py	2008-11-09 06:39:26 UTC (rev 5030)
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
-''' Nose test generators '''
+''' Nose test generators
+
+'''
 from os.path import join, dirname
 from glob import glob
 from StringIO import StringIO
@@ -19,7 +21,7 @@
 from numpy import array
 import scipy.sparse as SP
 
-from scipy.io.matlab.mio import loadmat, savemat
+from scipy.io.matlab.mio import loadmat, savemat, find_mat_file
 from scipy.io.matlab.mio5 import MatlabObject
 
 test_data_path = join(dirname(__file__), 'data')
@@ -311,23 +313,27 @@
     for filename in filenames:
         assert_raises(NotImplementedError, loadmat, filename, struct_as_record=True)
 
-def test_warn_struct_record():
-    # Use buffer hack to test for deprecation warning
-    warn_buf = StringIO()
-    base_show = warnings.showwarning
-    def showwarn(*args):
-        base_show(*args, **{'file':warn_buf})
+
+def test_warnings():
     fname = join(test_data_path, 'testdouble_7.1_GLNX86.mat')
+    warnings.simplefilter('error')
+    # This should not generate a warning
+    mres = loadmat(fname, struct_as_record=True)
+    # This neither
+    mres = loadmat(fname, struct_as_record=False)
+    # This should
+    yield assert_raises, FutureWarning, loadmat, fname
+    # This too
+    yield assert_raises, FutureWarning, find_mat_file, fname
+    # we need kwargs for this one
     try:
-        warnings.showwarning = showwarn
-        # This should not generate a deprecation warning
-        mres = loadmat(fname, struct_as_record=True)
-        yield assert_true, warn_buf.tell() == 0
-        # This neither
-        mres = loadmat(fname, struct_as_record=False)
-        yield assert_true, warn_buf.tell() == 0
-        # This should
-        mres = loadmat(fname)
-        yield assert_true, warn_buf.tell() > 0
-    finally:
-        warnings.showwarning = base_show
+        mres = loadmat(fname, struct_as_record=False, basename='raw')
+    except DeprecationWarning:
+        pass
+    else:
+        assert False, 'Did not raise deprecation warning'
+    # Test warning for default format change
+    savemat(StringIO(), {}, False, '4')
+    savemat(StringIO(), {}, False, '5')
+    yield assert_raises, FutureWarning, savemat, StringIO(), {}
+    warnings.resetwarnings()



More information about the Scipy-svn mailing list