@@ -2232,10 +2232,10 @@ def test_chunk_encoding_with_dask(self) -> None:
2232
2232
pass
2233
2233
2234
2234
def test_drop_encoding (self ):
2235
- ds = open_example_dataset ("example_1.nc" )
2236
- encodings = {v : {** ds [v ].encoding } for v in ds .data_vars }
2237
- with self .create_zarr_target () as store :
2238
- ds .to_zarr (store , encoding = encodings )
2235
+ with open_example_dataset ("example_1.nc" ) as ds :
2236
+ encodings = {v : {** ds [v ].encoding } for v in ds .data_vars }
2237
+ with self .create_zarr_target () as store :
2238
+ ds .to_zarr (store , encoding = encodings )
2239
2239
2240
2240
def test_hidden_zarr_keys (self ) -> None :
2241
2241
expected = create_test_data ()
@@ -4417,13 +4417,19 @@ def test_inline_array(self) -> None:
4417
4417
def num_graph_nodes (obj ):
4418
4418
return len (obj .__dask_graph__ ())
4419
4419
4420
- not_inlined_ds = open_dataset (tmp , inline_array = False , chunks = chunks )
4421
- inlined_ds = open_dataset (tmp , inline_array = True , chunks = chunks )
4422
- assert num_graph_nodes (inlined_ds ) < num_graph_nodes (not_inlined_ds )
4420
+ with open_dataset (
4421
+ tmp , inline_array = False , chunks = chunks
4422
+ ) as not_inlined_ds , open_dataset (
4423
+ tmp , inline_array = True , chunks = chunks
4424
+ ) as inlined_ds :
4425
+ assert num_graph_nodes (inlined_ds ) < num_graph_nodes (not_inlined_ds )
4423
4426
4424
- not_inlined_da = open_dataarray (tmp , inline_array = False , chunks = chunks )
4425
- inlined_da = open_dataarray (tmp , inline_array = True , chunks = chunks )
4426
- assert num_graph_nodes (inlined_da ) < num_graph_nodes (not_inlined_da )
4427
+ with open_dataarray (
4428
+ tmp , inline_array = False , chunks = chunks
4429
+ ) as not_inlined_da , open_dataarray (
4430
+ tmp , inline_array = True , chunks = chunks
4431
+ ) as inlined_da :
4432
+ assert num_graph_nodes (inlined_da ) < num_graph_nodes (not_inlined_da )
4427
4433
4428
4434
4429
4435
@requires_scipy_or_netCDF4
@@ -5335,8 +5341,8 @@ def test_raise_writing_to_nczarr(self, mode) -> None:
5335
5341
@requires_netCDF4
5336
5342
@requires_dask
5337
5343
def test_pickle_open_mfdataset_dataset ():
5338
- ds = open_example_mfdataset (["bears.nc" ])
5339
- assert_identical (ds , pickle .loads (pickle .dumps (ds )))
5344
+ with open_example_mfdataset (["bears.nc" ]) as ds :
5345
+ assert_identical (ds , pickle .loads (pickle .dumps (ds )))
5340
5346
5341
5347
5342
5348
@requires_zarr
0 commit comments