From cda8208a4b8a4eaa67f1f342795af68e708ec87a Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sat, 21 Dec 2013 15:50:05 +0100 Subject: [PATCH] TST: add regression test for gh-1550 (netcdf_file leaves mmaps open). --- scipy/io/tests/test_netcdf.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scipy/io/tests/test_netcdf.py b/scipy/io/tests/test_netcdf.py index a5a5b8898dd8..d1686cd77c73 100644 --- a/scipy/io/tests/test_netcdf.py +++ b/scipy/io/tests/test_netcdf.py @@ -5,14 +5,12 @@ from os.path import join as pjoin, dirname import shutil import tempfile -import time -import sys from io import BytesIO from glob import glob from contextlib import contextmanager import numpy as np -from numpy.testing import dec, assert_, assert_allclose +from numpy.testing import assert_, assert_allclose from scipy.io.netcdf import netcdf_file @@ -198,3 +196,14 @@ def test_ticket_1720(): assert_equal(float_var.units, b'metres') assert_equal(float_var.shape, (10,)) assert_allclose(float_var[:], items) + + +def test_mmaps_closed(): + # Regression test for gh-1550. Will fail with "Too many open files" + # error if not all mmaps aren't closed by ``f.close()``. + filename = pjoin(TEST_DATA_PATH, 'example_1.nc') + vars = [] + for i in range(1100): + f = netcdf_file(filename, mmap=True) + vars.append(f.variables['lat']) + f.close()