Skip to content

Commit 98dc178

Browse files
committed
Use context managers in test functions
Elimiinate 32 of 70 of the following warnings emitted while running unit tests: `RuntimeWarning: deallocating CachingFileManager` The remaining 38 appear to all be related to the HDF5VirtualBackend (see #468) Fixes #390
1 parent 556ef97 commit 98dc178

File tree

7 files changed

+481
-395
lines changed

7 files changed

+481
-395
lines changed

conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def netcdf4_file_with_data_in_multiple_groups(tmp_path: Path) -> str:
6161

6262

6363
@pytest.fixture
64-
def netcdf4_files_factory(tmp_path: Path) -> Callable:
64+
def netcdf4_files_factory(tmp_path: Path) -> Callable[[], tuple[str, str]]:
6565
def create_netcdf4_files(
6666
encoding: Optional[Mapping[str, Mapping[str, Any]]] = None,
6767
) -> tuple[str, str]:
@@ -96,7 +96,8 @@ def netcdf4_file_with_2d_coords(tmp_path: Path) -> str:
9696
def netcdf4_virtual_dataset(netcdf4_file):
9797
from virtualizarr import open_virtual_dataset
9898

99-
return open_virtual_dataset(netcdf4_file, indexes={})
99+
with open_virtual_dataset(netcdf4_file, indexes={}) as ds:
100+
yield ds
100101

101102

102103
@pytest.fixture

virtualizarr/backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ def open_virtual_dataset(
109109
cftime_variables: Iterable[str] | None = None,
110110
indexes: Mapping[str, Index] | None = None,
111111
virtual_array_class=ManifestArray,
112-
virtual_backend_kwargs: Optional[dict] = None,
113-
reader_options: Optional[dict] = None,
114-
backend: Optional[VirtualBackend] = None,
112+
virtual_backend_kwargs: dict | None = None,
113+
reader_options: dict | None = None,
114+
backend: type[VirtualBackend] | None = None,
115115
) -> Dataset:
116116
"""
117117
Open a file or store as an xarray Dataset wrapping virtualized zarr arrays.

0 commit comments

Comments
 (0)