[Scipy-svn] r7160 - in branches/0.9.x/scipy: misc/tests ndimage spatial/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sun Feb 20 04:35:12 EST 2011


Author: rgommers
Date: 2011-02-20 03:35:12 -0600 (Sun, 20 Feb 2011)
New Revision: 7160

Modified:
   branches/0.9.x/scipy/misc/tests/test_pilutil.py
   branches/0.9.x/scipy/ndimage/io.py
   branches/0.9.x/scipy/spatial/tests/test_distance.py
Log:
TST: explicit file close to avoid ResourceWarnings under Python 3.2.

Thanks to Christoph Gohlke.

(backport of r7147)

Modified: branches/0.9.x/scipy/misc/tests/test_pilutil.py
===================================================================
--- branches/0.9.x/scipy/misc/tests/test_pilutil.py	2011-02-20 09:34:37 UTC (rev 7159)
+++ branches/0.9.x/scipy/misc/tests/test_pilutil.py	2011-02-20 09:35:12 UTC (rev 7160)
@@ -42,7 +42,9 @@
         assert_equal(pilutil.bytescale(y),[0,127,255])
 
 def tst_fromimage(filename, irange):
-    img = pilutil.fromimage(PIL.Image.open(filename))
+    fp = open(filename, "rb")
+    img = pilutil.fromimage(PIL.Image.open(fp))
+    fp.close()
     imin,imax = irange
     assert_(img.min() >= imin)
     assert_(img.max() <= imax)

Modified: branches/0.9.x/scipy/ndimage/io.py
===================================================================
--- branches/0.9.x/scipy/ndimage/io.py	2011-02-20 09:34:37 UTC (rev 7159)
+++ branches/0.9.x/scipy/ndimage/io.py	2011-02-20 09:35:12 UTC (rev 7160)
@@ -34,8 +34,10 @@
                           " http://pypi.python.org/pypi/PIL/ for installation"
                           " instructions.")
 
-    im = Image.open(fname)
+    fp = open(fname, "rb")
+    im = Image.open(fp)
     if flatten:
         im = im.convert('F')
-    return array(im)
-
+    result = array(im)
+    fp.close()
+    return result

Modified: branches/0.9.x/scipy/spatial/tests/test_distance.py
===================================================================
--- branches/0.9.x/scipy/spatial/tests/test_distance.py	2011-02-20 09:34:37 UTC (rev 7159)
+++ branches/0.9.x/scipy/spatial/tests/test_distance.py	2011-02-20 09:35:12 UTC (rev 7160)
@@ -88,7 +88,9 @@
     for fn in _filenames:
         name = fn.replace(".txt", "").replace("-ml", "")
         fqfn = os.path.join(os.path.dirname(__file__), fn)
-        eo[name] = np.loadtxt(open(fqfn))
+        fp = open(fqfn)
+        eo[name] = np.loadtxt(fp)
+        fp.close()
         #print "%s: %s   %s" % (name, str(eo[name].shape), str(eo[name].dtype))
     eo['pdist-boolean-inp'] = np.bool_(eo['pdist-boolean-inp'])
 




More information about the Scipy-svn mailing list