Ensure that if `ZarrStore` is created with `cache_members` set to `True`, a `ZarrStore` only inspects the underlying zarr group once, and that the results of that inspection are cached. Otherwise, `ZarrStore.members` should inspect the underlying zarr group each tim
(self)
| 3771 | assert original.chunks == actual.chunks |
| 3772 | |
| 3773 | def test_cache_members(self) -> None: |
| 3774 | """ |
| 3775 | Ensure that if `ZarrStore` is created with `cache_members` set to `True`, |
| 3776 | a `ZarrStore` only inspects the underlying zarr group once, |
| 3777 | and that the results of that inspection are cached. |
| 3778 | |
| 3779 | Otherwise, `ZarrStore.members` should inspect the underlying zarr group each time it is |
| 3780 | invoked |
| 3781 | """ |
| 3782 | with self.create_zarr_target() as store_target: |
| 3783 | zstore_mut = backends.ZarrStore.open_group( |
| 3784 | store_target, mode="w", cache_members=False |
| 3785 | ) |
| 3786 | |
| 3787 | # ensure that the keys are sorted |
| 3788 | array_keys = sorted(("foo", "bar")) |
| 3789 | |
| 3790 | # create some arrays |
| 3791 | for ak in array_keys: |
| 3792 | zstore_mut.zarr_group.create(name=ak, shape=(1,), dtype="uint8") |
| 3793 | |
| 3794 | zstore_stat = backends.ZarrStore.open_group( |
| 3795 | store_target, mode="r", cache_members=True |
| 3796 | ) |
| 3797 | |
| 3798 | observed_keys_0 = sorted(zstore_stat.array_keys()) |
| 3799 | assert observed_keys_0 == array_keys |
| 3800 | |
| 3801 | # create a new array |
| 3802 | new_key = "baz" |
| 3803 | zstore_mut.zarr_group.create(name=new_key, shape=(1,), dtype="uint8") |
| 3804 | |
| 3805 | observed_keys_1 = sorted(zstore_stat.array_keys()) |
| 3806 | assert observed_keys_1 == array_keys |
| 3807 | |
| 3808 | observed_keys_2 = sorted(zstore_mut.array_keys()) |
| 3809 | assert observed_keys_2 == sorted(array_keys + [new_key]) |
| 3810 | |
| 3811 | @requires_dask |
| 3812 | @pytest.mark.parametrize("dtype", [int, float]) |
nothing calls this directly
no test coverage detected