diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2015-12-20 10:47:42 -0700 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2015-12-20 10:47:42 -0700 |
| commit | 765422cfa5a959985808bbf11f7a6a58a9dc5e46 (patch) | |
| tree | 23be151e3ee2dc61441a024d7ff047ff3e4d35f4 /numpy/lib | |
| parent | f125b7d456717b366df1ed756656e3670a8a8d54 (diff) | |
| parent | c4156cfbe9c22ab99473346b7757d2b54b46baa3 (diff) | |
| download | numpy-765422cfa5a959985808bbf11f7a6a58a9dc5e46.tar.gz | |
Merge pull request #6866 from charris/tempfile-context-manager
ENH: Tempfile context manager
Diffstat (limited to 'numpy/lib')
| -rw-r--r-- | numpy/lib/tests/test_io.py | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index bffc5c63e..45ee0a477 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -19,7 +19,7 @@ from numpy.ma.testutils import assert_equal from numpy.testing import ( TestCase, run_module_suite, assert_warns, assert_, assert_raises_regex, assert_raises, assert_allclose, - assert_array_equal, + assert_array_equal,temppath ) from numpy.testing.utils import tempdir @@ -259,26 +259,17 @@ class TestSavezLoad(RoundtripTest, TestCase): def test_not_closing_opened_fid(self): # Test that issue #2178 is fixed: # verify could seek on 'loaded' file - - fd, tmp = mkstemp(suffix='.npz') - os.close(fd) - try: - fp = open(tmp, 'wb') - np.savez(fp, data='LOVELY LOAD') - fp.close() - - fp = open(tmp, 'rb', 10000) - fp.seek(0) - assert_(not fp.closed) - np.load(fp)['data'] - # fp must not get closed by .load - assert_(not fp.closed) - fp.seek(0) - assert_(not fp.closed) - - finally: - fp.close() - os.remove(tmp) + with temppath(suffix='.npz') as tmp: + with open(tmp, 'wb') as fp: + np.savez(fp, data='LOVELY LOAD') + with open(tmp, 'rb', 10000) as fp: + fp.seek(0) + assert_(not fp.closed) + np.load(fp)['data'] + # fp must not get closed by .load + assert_(not fp.closed) + fp.seek(0) + assert_(not fp.closed) def test_closing_fid(self): # Test that issue #1517 (too many opened files) remains closed |
