Test `open_groups` with a netCDF4 file with an unaligned group hierarchy.
(self, unaligned_datatree_nc)
| 421 | open_datatree(unaligned_datatree_nc) |
| 422 | |
| 423 | def test_open_groups(self, unaligned_datatree_nc) -> None: |
| 424 | """Test `open_groups` with a netCDF4 file with an unaligned group hierarchy.""" |
| 425 | unaligned_dict_of_datasets = open_groups(unaligned_datatree_nc) |
| 426 | |
| 427 | # Check that group names are keys in the dictionary of `xr.Datasets` |
| 428 | assert "/" in unaligned_dict_of_datasets.keys() |
| 429 | assert "/Group1" in unaligned_dict_of_datasets.keys() |
| 430 | assert "/Group1/subgroup1" in unaligned_dict_of_datasets.keys() |
| 431 | # Check that group name returns the correct datasets |
| 432 | with xr.open_dataset(unaligned_datatree_nc, group="/") as expected: |
| 433 | assert_identical(unaligned_dict_of_datasets["/"], expected) |
| 434 | with xr.open_dataset(unaligned_datatree_nc, group="Group1") as expected: |
| 435 | assert_identical(unaligned_dict_of_datasets["/Group1"], expected) |
| 436 | with xr.open_dataset( |
| 437 | unaligned_datatree_nc, group="/Group1/subgroup1" |
| 438 | ) as expected: |
| 439 | assert_identical(unaligned_dict_of_datasets["/Group1/subgroup1"], expected) |
| 440 | |
| 441 | for ds in unaligned_dict_of_datasets.values(): |
| 442 | ds.close() |
| 443 | |
| 444 | @requires_dask |
| 445 | def test_open_groups_chunks(self, tmpdir) -> None: |
nothing calls this directly
no test coverage detected