|
17 | 17 | open,
|
18 | 18 | open_consolidated,
|
19 | 19 | )
|
20 |
| -from zarr.core.buffer import default_buffer_prototype |
| 20 | +from zarr.core.buffer import 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
|
@@ -476,6 +476,30 @@ async def test_open_consolidated_raises_async(self, zarr_format: ZarrFormat):
|
476 | 476 | with pytest.raises(ValueError):
|
477 | 477 | await zarr.api.asynchronous.open_consolidated(store, zarr_format=None)
|
478 | 478 |
|
| 479 | + @pytest.fixture |
| 480 | + async def v2_consolidated_metadata_empty_dataset( |
| 481 | + self, memory_store: zarr.storage.MemoryStore |
| 482 | + ) -> AsyncGroup: |
| 483 | + zgroup_bytes = cpu.Buffer.from_bytes(json.dumps({"zarr_format": 2}).encode()) |
| 484 | + zmetadata_bytes = cpu.Buffer.from_bytes( |
| 485 | + b'{"metadata":{".zgroup":{"zarr_format":2}},"zarr_consolidated_format":1}' |
| 486 | + ) |
| 487 | + return AsyncGroup._from_bytes_v2( |
| 488 | + None, zgroup_bytes, zattrs_bytes=None, consolidated_metadata_bytes=zmetadata_bytes |
| 489 | + ) |
| 490 | + |
| 491 | + async def test_consolidated_metadata_backwards_compatibility( |
| 492 | + self, v2_consolidated_metadata_empty_dataset |
| 493 | + ): |
| 494 | + """ |
| 495 | + Test that consolidated metadata handles a missing .zattrs key. This is necessary for backwards compatibility with zarr-python 2.x. See https://github.com/zarr-developers/zarr-python/issues/2694 |
| 496 | + """ |
| 497 | + store = zarr.storage.MemoryStore() |
| 498 | + await zarr.api.asynchronous.open(store=store, zarr_format=2) |
| 499 | + await zarr.api.asynchronous.consolidate_metadata(store) |
| 500 | + result = await zarr.api.asynchronous.open_consolidated(store, zarr_format=2) |
| 501 | + assert result.metadata == v2_consolidated_metadata_empty_dataset.metadata |
| 502 | + |
479 | 503 | async def test_consolidated_metadata_v2(self):
|
480 | 504 | store = zarr.storage.MemoryStore()
|
481 | 505 | g = await AsyncGroup.from_store(store, attributes={"key": "root"}, zarr_format=2)
|
|
0 commit comments