Skip to content

Commit 92f79a0

Browse files
authored
Silence a bunch of CachingFileManager warnings (#8584)
* Silence a bunch of CachingFileManager warnings * Silence more.
1 parent 1ebd3dd commit 92f79a0

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

xarray/tests/test_backends.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,10 +2232,10 @@ def test_chunk_encoding_with_dask(self) -> None:
22322232
pass
22332233

22342234
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)
22392239

22402240
def test_hidden_zarr_keys(self) -> None:
22412241
expected = create_test_data()
@@ -4417,13 +4417,19 @@ def test_inline_array(self) -> None:
44174417
def num_graph_nodes(obj):
44184418
return len(obj.__dask_graph__())
44194419

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)
44234426

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)
44274433

44284434

44294435
@requires_scipy_or_netCDF4
@@ -5335,8 +5341,8 @@ def test_raise_writing_to_nczarr(self, mode) -> None:
53355341
@requires_netCDF4
53365342
@requires_dask
53375343
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)))
53405346

53415347

53425348
@requires_zarr

0 commit comments

Comments
 (0)