(self)
| 295 | |
| 296 | @pytest.mark.slow_pypy |
| 297 | def test_closing_fid(self): |
| 298 | # Test that issue #1517 (too many opened files) remains closed |
| 299 | # It might be a "weak" test since failed to get triggered on |
| 300 | # e.g. Debian sid of 2012 Jul 05 but was reported to |
| 301 | # trigger the failure on Ubuntu 10.04: |
| 302 | # http://projects.scipy.org/numpy/ticket/1517#comment:2 |
| 303 | with temppath(suffix='.npz') as tmp: |
| 304 | np.savez(tmp, data='LOVELY LOAD') |
| 305 | # We need to check if the garbage collector can properly close |
| 306 | # numpy npz file returned by np.load when their reference count |
| 307 | # goes to zero. Python 3 running in debug mode raises a |
| 308 | # ResourceWarning when file closing is left to the garbage |
| 309 | # collector, so we catch the warnings. |
| 310 | with suppress_warnings() as sup: |
| 311 | sup.filter(ResourceWarning) # TODO: specify exact message |
| 312 | for i in range(1, 1025): |
| 313 | try: |
| 314 | np.load(tmp)["data"] |
| 315 | except Exception as e: |
| 316 | msg = "Failed to load data from a file: %s" % e |
| 317 | raise AssertionError(msg) |
| 318 | finally: |
| 319 | if IS_PYPY: |
| 320 | gc.collect() |
| 321 | |
| 322 | def test_closing_zipfile_after_load(self): |
| 323 | # Check that zipfile owns file and can close it. This needs to |
nothing calls this directly
no test coverage detected