|
89 | 89 | requires_scipy,
|
90 | 90 | requires_scipy_or_netCDF4,
|
91 | 91 | requires_zarr,
|
| 92 | + requires_zarr_v3, |
92 | 93 | )
|
93 | 94 | from xarray.tests.test_coding_times import (
|
94 | 95 | _ALL_CALENDARS,
|
|
117 | 118 |
|
118 | 119 | if has_zarr_v3:
|
119 | 120 | from zarr.storage import MemoryStore as KVStore
|
| 121 | + from zarr.storage import WrapperStore |
120 | 122 |
|
121 | 123 | ZARR_FORMATS = [2, 3]
|
122 | 124 | else:
|
|
127 | 129 | )
|
128 | 130 | except ImportError:
|
129 | 131 | KVStore = None # type: ignore[assignment,misc,unused-ignore]
|
| 132 | + |
| 133 | + WrapperStore = object # type: ignore[assignment,misc,unused-ignore] |
130 | 134 | else:
|
131 | 135 | KVStore = None # type: ignore[assignment,misc,unused-ignore]
|
| 136 | + WrapperStore = object # type: ignore[assignment,misc,unused-ignore] |
132 | 137 | ZARR_FORMATS = []
|
133 | 138 |
|
134 | 139 |
|
@@ -2400,12 +2405,13 @@ def test_read_non_consolidated_warning(self) -> None:
|
2400 | 2405 | self.save(
|
2401 | 2406 | expected, store_target=store, consolidated=False, **self.version_kwargs
|
2402 | 2407 | )
|
2403 |
| - with pytest.warns( |
2404 |
| - RuntimeWarning, |
2405 |
| - match="Failed to open Zarr store with consolidated", |
2406 |
| - ): |
2407 |
| - with xr.open_zarr(store, **self.version_kwargs) as ds: |
2408 |
| - assert_identical(ds, expected) |
| 2408 | + if getattr(store, "supports_consolidated_metadata", True): |
| 2409 | + with pytest.warns( |
| 2410 | + RuntimeWarning, |
| 2411 | + match="Failed to open Zarr store with consolidated", |
| 2412 | + ): |
| 2413 | + with xr.open_zarr(store, **self.version_kwargs) as ds: |
| 2414 | + assert_identical(ds, expected) |
2409 | 2415 |
|
2410 | 2416 | def test_non_existent_store(self) -> None:
|
2411 | 2417 | with pytest.raises(
|
@@ -3756,6 +3762,42 @@ def test_chunk_key_encoding_v2(self) -> None:
|
3756 | 3762 | assert actual["var1"].encoding["chunks"] == (2, 2)
|
3757 | 3763 |
|
3758 | 3764 |
|
| 3765 | +class NoConsolidatedMetadataSupportStore(WrapperStore): |
| 3766 | + """ |
| 3767 | + Store that explicitly does not support consolidated metadata. |
| 3768 | +
|
| 3769 | + Useful as a proxy for stores like Icechunk, see https://github.com/zarr-developers/zarr-python/pull/3119. |
| 3770 | + """ |
| 3771 | + |
| 3772 | + supports_consolidated_metadata = False |
| 3773 | + |
| 3774 | + def __init__( |
| 3775 | + self, |
| 3776 | + store, |
| 3777 | + *, |
| 3778 | + read_only: bool = False, |
| 3779 | + ) -> None: |
| 3780 | + self._store = store.with_read_only(read_only=read_only) |
| 3781 | + |
| 3782 | + def with_read_only( |
| 3783 | + self, read_only: bool = False |
| 3784 | + ) -> NoConsolidatedMetadataSupportStore: |
| 3785 | + return type(self)( |
| 3786 | + store=self._store, |
| 3787 | + read_only=read_only, |
| 3788 | + ) |
| 3789 | + |
| 3790 | + |
| 3791 | +@requires_zarr_v3 |
| 3792 | +class TestZarrNoConsolidatedMetadataSupport(ZarrBase): |
| 3793 | + @contextlib.contextmanager |
| 3794 | + def create_zarr_target(self): |
| 3795 | + # TODO the zarr version would need to be >3.08 for the supports_consolidated_metadata property to have any effect |
| 3796 | + yield NoConsolidatedMetadataSupportStore( |
| 3797 | + zarr.storage.MemoryStore({}, read_only=False) |
| 3798 | + ) |
| 3799 | + |
| 3800 | + |
3759 | 3801 | @requires_zarr
|
3760 | 3802 | @pytest.mark.skipif(
|
3761 | 3803 | ON_WINDOWS,
|
|
0 commit comments