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

scipy-svn@scip... scipy-svn@scip...
Mon Jun 9 22:40:59 CDT 2008


Author: wnbell
Date: 2008-06-09 22:40:56 -0500 (Mon, 09 Jun 2008)
New Revision: 4422

Modified:
   trunk/scipy/io/matlab/miobase.py
   trunk/scipy/io/matlab/tests/test_mio.py
Log:
Added patch by Andrew Straw to fix MATLAB support on gzip files
resolves ticket #682


Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py	2008-06-09 22:42:02 UTC (rev 4421)
+++ trunk/scipy/io/matlab/miobase.py	2008-06-10 03:40:56 UTC (rev 4422)
@@ -284,7 +284,8 @@
 
     def end_of_stream(self):
         b = self.mat_stream.read(1)
-        self.mat_stream.seek(-1,1)
+        curpos = self.mat_stream.tell()
+        self.mat_stream.seek(curpos-1)
         return len(b) == 0
 
 

Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py	2008-06-09 22:42:02 UTC (rev 4421)
+++ trunk/scipy/io/matlab/tests/test_mio.py	2008-06-10 03:40:56 UTC (rev 4422)
@@ -3,7 +3,7 @@
 import os
 from glob import glob
 from cStringIO import StringIO
-from tempfile import mkstemp
+from tempfile import mkstemp, mkdtemp
 from scipy.testing import *
 from numpy import arange, array, eye, pi, cos, exp, sin, sqrt, ndarray,  \
      zeros, reshape, transpose, empty
@@ -12,6 +12,9 @@
 from scipy.io.matlab.mio import loadmat, savemat
 from scipy.io.matlab.mio5 import mat_obj, mat_struct
 
+import shutil
+import gzip
+
 try:  # Python 2.3 support
     from sets import Set as set
 except:
@@ -238,3 +241,29 @@
         expected = case['expected']
         format = case in case_table4 and '4' or '5'
         yield _make_rt_check_case, name, expected, format
+
+def test_gzip_simple():
+    xdense = zeros((20,20))
+    xdense[2,3]=2.3
+    xdense[4,5]=4.5
+    x = SP.csc_matrix(xdense)
+
+    name = 'gzip_test'
+    expected = {'x':x}
+    format='4'
+
+    tmpdir = mkdtemp()
+    try:
+        fname = os.path.join(tmpdir,name)
+        mat_stream = gzip.open( fname,mode='wb')
+        savemat(mat_stream, expected, format=format)
+        mat_stream.close()
+
+        mat_stream = gzip.open( fname,mode='rb')
+        actual = loadmat(mat_stream)
+        mat_stream.close()
+    finally:
+        shutil.rmtree(tmpdir)
+
+    assert_array_almost_equal(actual['x'].todense(),
+                              expected['x'].todense())



More information about the Scipy-svn mailing list