Skip to content
Browse files

TST: explicit file close to avoid ResourceWarnings under Python 3.2.

Thanks to Christoph Gohlke.

(backport of r7147)
  • Loading branch information...
1 parent 4708749 commit 4bb65dc76585cc5b0fb36f08ad24e06b9cb642f8 @rgommers rgommers committed Feb 20, 2011
Showing with 11 additions and 5 deletions.
  1. +3 −1 scipy/misc/tests/test_pilutil.py
  2. +5 −3 scipy/ndimage/io.py
  3. +3 −1 scipy/spatial/tests/test_distance.py
View
4 scipy/misc/tests/test_pilutil.py
@@ -42,7 +42,9 @@ def test_bytescale(self):
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)
View
8 scipy/ndimage/io.py
@@ -34,8 +34,10 @@ def imread(fname, flatten=False):
" 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
View
4 scipy/spatial/tests/test_distance.py
@@ -88,7 +88,9 @@ def load_testing_files():
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'])

0 comments on commit 4bb65dc

Please sign in to comment.
Something went wrong with that request. Please try again.