MCPcopy Index your code
hub / github.com/pydata/xarray / test_open_groups

Method test_open_groups

xarray/tests/test_backends_datatree.py:979–1002  ·  view source on GitHub ↗

Test `open_groups` with a zarr store of an unaligned group hierarchy.

(self, unaligned_datatree_zarr_factory, zarr_format)

Source from the content-addressed store, hash-verified

977 "ignore:Failed to open Zarr store with consolidated metadata:RuntimeWarning"
978 )
979 def test_open_groups(self, unaligned_datatree_zarr_factory, zarr_format) -> None:
980 """Test `open_groups` with a zarr store of an unaligned group hierarchy."""
981
982 storepath = unaligned_datatree_zarr_factory(zarr_format=zarr_format)
983 unaligned_dict_of_datasets = open_groups(storepath, engine="zarr")
984
985 assert "/" in unaligned_dict_of_datasets.keys()
986 assert "/Group1" in unaligned_dict_of_datasets.keys()
987 assert "/Group1/subgroup1" in unaligned_dict_of_datasets.keys()
988 assert "/Group2" in unaligned_dict_of_datasets.keys()
989 # Check that group name returns the correct datasets
990 with xr.open_dataset(storepath, group="/", engine="zarr") as expected:
991 assert_identical(unaligned_dict_of_datasets["/"], expected)
992 with xr.open_dataset(storepath, group="Group1", engine="zarr") as expected:
993 assert_identical(unaligned_dict_of_datasets["/Group1"], expected)
994 with xr.open_dataset(
995 storepath, group="/Group1/subgroup1", engine="zarr"
996 ) as expected:
997 assert_identical(unaligned_dict_of_datasets["/Group1/subgroup1"], expected)
998 with xr.open_dataset(storepath, group="/Group2", engine="zarr") as expected:
999 assert_identical(unaligned_dict_of_datasets["/Group2"], expected)
1000
1001 for ds in unaligned_dict_of_datasets.values():
1002 ds.close()
1003
1004 @pytest.mark.filterwarnings(
1005 "ignore:Failed to open Zarr store with consolidated metadata:RuntimeWarning"

Callers

nothing calls this directly

Calls 7

open_groupsFunction · 0.90
assert_identicalFunction · 0.90
keysMethod · 0.80
open_datasetMethod · 0.45
valuesMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected