|
17 | 17 | open, |
18 | 18 | open_consolidated, |
19 | 19 | ) |
20 | | -from zarr.core.buffer import cpu, default_buffer_prototype |
| 20 | +from zarr.core.buffer import Buffer, cpu, default_buffer_prototype |
21 | 21 | from zarr.core.group import ConsolidatedMetadata, GroupMetadata |
22 | 22 | from zarr.core.metadata import ArrayV3Metadata |
23 | 23 | from zarr.core.metadata.v2 import ArrayV2Metadata |
24 | 24 | from zarr.storage import StorePath |
25 | 25 |
|
26 | 26 | if TYPE_CHECKING: |
27 | | - from zarr.abc.store import Store |
| 27 | + from zarr.abc.store import ByteRequest, Store |
28 | 28 | from zarr.core.common import ZarrFormat |
29 | 29 |
|
30 | 30 |
|
@@ -651,3 +651,27 @@ async def test_consolidated_metadata_encodes_special_chars( |
651 | 651 | elif zarr_format == 3: |
652 | 652 | assert root_metadata["child"]["attributes"]["test"] == expected_fill_value |
653 | 653 | assert root_metadata["time"]["fill_value"] == expected_fill_value |
| 654 | + |
| 655 | + |
| 656 | +async def test_consolidate_metadata_is_noop_for_self_consolidating_stores(): |
| 657 | + """Verify calling consolidate_metadata on a non supporting stores does nothing""" |
| 658 | + |
| 659 | + # We create a store that doesn't support consolidated metadata |
| 660 | + class Store(zarr.storage.MemoryStore): |
| 661 | + @property |
| 662 | + def supports_consolidated_metadata(self) -> bool: |
| 663 | + return False |
| 664 | + |
| 665 | + memory_store = Store() |
| 666 | + root = await zarr.api.asynchronous.create_group(store=memory_store) |
| 667 | + await root.create_group("a/b") |
| 668 | + |
| 669 | + # now we monkey patch the store so it raises if `Store.set` is called |
| 670 | + async def set_raises(self, value: Buffer, byte_range: ByteRequest | None = None) -> None: |
| 671 | + raise ValueError("consolidated metadata called") |
| 672 | + |
| 673 | + memory_store.set = set_raises |
| 674 | + |
| 675 | + # consolidate_metadata would call `set` if the store supported consolidated metadata |
| 676 | + # if this doesn't raise, it means consolidate_metadata is NOOP |
| 677 | + await zarr.api.asynchronous.consolidate_metadata(memory_store) |
0 commit comments