Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Close fd temp file following rec2csv_bad_shape test #971

Merged
merged 1 commit into from

4 participants

@jenshnielsen

This avoids a warning in python3 about the unclosed file
and potential side effects of the open file.

@WeatherGod
Collaborator

Shouldn't it close when the object goes out of scope anyway? I don't see any harm in including this code (the ValueError exception should still bubble up to nose). I just wanted to make sure I understood tempfile correctly.

@jdh2358
Owner

If this is a fix for python3, shouldn't it go against master rather than 1.1.x, which doesn't support python3?

@jenshnielsen
Owner

Well I can rebase it against master and thats fine with me, but I believe the behavior is the same on the different python versions the only difference is that python 3 gives the not closed warning while python2 does not, thus it seems like a good idea to close the temp file in any case.
I think the tempfile is closed when it goes out of scope but I think the main point is that the file is destroyed when it is closed. http://docs.python.org/library/tempfile.html

@mdboom
Owner

+1

@WeatherGod
Collaborator

In any case, explicit is better than implicit. I am fine with it being merged in.

@mdboom mdboom merged commit 2c85848 into matplotlib:v1.1.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/matplotlib/tests/test_mlab.py
View
13 lib/matplotlib/tests/test_mlab.py
@@ -27,11 +27,14 @@ def test_recarray_csv_roundtrip():
@raises(ValueError)
def test_rec2csv_bad_shape():
- bad = np.recarray((99,4),[('x',np.float),('y',np.float)])
- fd = tempfile.TemporaryFile(suffix='csv')
-
- # the bad recarray should trigger a ValueError for having ndim > 1.
- mlab.rec2csv(bad,fd)
+ try:
+ bad = np.recarray((99,4),[('x',np.float),('y',np.float)])
+ fd = tempfile.TemporaryFile(suffix='csv')
+
+ # the bad recarray should trigger a ValueError for having ndim > 1.
+ mlab.rec2csv(bad,fd)
+ finally:
+ fd.close()
def test_prctile():
# test odd lengths
Something went wrong with that request. Please try again.