diff options
| author | njsmith <njs@pobox.com> | 2013-03-04 11:06:44 -0800 |
|---|---|---|
| committer | njsmith <njs@pobox.com> | 2013-03-04 11:06:44 -0800 |
| commit | 3ba223e867dd6a2bda130d0630ee9aad3c32ae97 (patch) | |
| tree | 2b5569c92f2cc937ef65de0e4dfc9ebe1f0c21cd /numpy | |
| parent | e1055868eb6c015a568f0ccff29b37d1e3970242 (diff) | |
| parent | 31a68dde93137eef779addb005f82ce0a57585e4 (diff) | |
| download | numpy-3ba223e867dd6a2bda130d0630ee9aad3c32ae97.tar.gz | |
Merge pull request #3114 from charris/fix-resource-warnings
Fix resource warnings
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/distutils/system_info.py | 7 | ||||
| -rw-r--r-- | numpy/lib/tests/test_io.py | 21 |
2 files changed, 21 insertions, 7 deletions
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index 68a9ba5a9..1f3ce2ddb 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -218,8 +218,11 @@ else: import subprocess as sp try: + # Explicitly open/close file to avoid ResourceWarning when + # tests are run in debug mode Python 3. + tmp = open(os.devnull, 'w') p = sp.Popen(["gcc", "-print-multiarch"], stdout=sp.PIPE, - stderr=open(os.devnull, 'w')) + stderr=tmp) except OSError: pass # gcc is not installed else: @@ -228,6 +231,8 @@ else: # gcc supports the "-print-multiarch" option default_x11_lib_dirs += [os.path.join("/usr/lib/", triplet)] default_lib_dirs += [os.path.join("/usr/lib/", triplet)] + finally: + tmp.close() if os.path.join(sys.prefix, 'lib') not in default_lib_dirs: default_lib_dirs.insert(0, os.path.join(sys.prefix, 'lib')) 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) |
