diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-03-03 15:23:02 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-03-03 18:19:15 -0700 |
commit | 31a68dde93137eef779addb005f82ce0a57585e4 (patch) | |
tree | 25751af425ac65944ec10ae018b0746c3929b6be /numpy/lib/tests/test_io.py | |
parent | 96ea318b10e31c405798a3f96d93b418d188969d (diff) | |
download | numpy-31a68dde93137eef779addb005f82ce0a57585e4.tar.gz |
TST: Get rid of a ResourceWarning.
I'm not sure this is the right fix, but test_closing_fid need to check
that garbage collection will close a file that goes through a bunch of
openings followed by dropping the reference. So the fix is to ignore
warnings during the test. I'd just ignore ResourceWarning, but it does
not look to be a built in warning in Python 2.7.
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index f1088ebb5..9144138d1 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -205,12 +205,21 @@ class TestSavezLoad(RoundtripTest, TestCase): fp = open(tmp, 'wb') np.savez(fp, data='LOVELY LOAD') fp.close() - - for i in range(1, 1025): - try: - np.load(tmp)["data"] - except Exception as e: - raise AssertionError("Failed to load data from a file: %s" % e) + # We need to check if the garbage collector can properly close + # numpy npz file returned by np.load when their reference count + # goes to zero. Python 3 running in debug mode raises a + # ResourceWarning when file closing is left to the garbage + # collector, so we catch the warnings. Because ResourceWarning + # is unknown in Python < 3.x, we take the easy way out and + # catch all warnings. + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + for i in range(1, 1025): + try: + np.load(tmp)["data"] + except Exception as e: + msg = "Failed to load data from a file: %s" % e + raise AssertionError(msg) finally: os.remove(tmp) |