|
19 | 19 | from zarr.core.buffer.core import default_buffer_prototype |
20 | 20 | from zarr.core.group import ConsolidatedMetadata, GroupMetadata |
21 | 21 | from zarr.core.metadata import ArrayV3Metadata |
| 22 | +from zarr.core.metadata.v2 import ArrayV2Metadata |
22 | 23 | from zarr.store.common import StorePath |
23 | 24 |
|
24 | 25 | if TYPE_CHECKING: |
@@ -479,3 +480,44 @@ async def test_open_consolidated_raises_async(self, zarr_format: ZarrFormat): |
479 | 480 |
|
480 | 481 | with pytest.raises(ValueError): |
481 | 482 | await zarr.api.asynchronous.open_consolidated(store, zarr_format=None) |
| 483 | + |
| 484 | + async def test_consolidated_metadata_v2(self): |
| 485 | + store = zarr.store.MemoryStore(mode="w") |
| 486 | + g = await AsyncGroup.from_store(store, attributes={"key": "root"}, zarr_format=2) |
| 487 | + await g.create_array(name="a", shape=(1,), attributes={"key": "a"}) |
| 488 | + g1 = await g.create_group(name="g1", attributes={"key": "g1"}) |
| 489 | + await g1.create_group(name="g2", attributes={"key": "g2"}) |
| 490 | + |
| 491 | + await zarr.api.asynchronous.consolidate_metadata(store) |
| 492 | + result = await zarr.api.asynchronous.open_consolidated(store, zarr_format=2) |
| 493 | + |
| 494 | + expected = GroupMetadata( |
| 495 | + attributes={"key": "root"}, |
| 496 | + zarr_format=2, |
| 497 | + consolidated_metadata=ConsolidatedMetadata( |
| 498 | + metadata={ |
| 499 | + "a": ArrayV2Metadata( |
| 500 | + shape=(1,), |
| 501 | + dtype="float64", |
| 502 | + attributes={"key": "a"}, |
| 503 | + chunks=(1,), |
| 504 | + fill_value=0.0, |
| 505 | + order="C", |
| 506 | + ), |
| 507 | + "g1": GroupMetadata( |
| 508 | + attributes={"key": "g1"}, |
| 509 | + zarr_format=2, |
| 510 | + consolidated_metadata=ConsolidatedMetadata( |
| 511 | + metadata={ |
| 512 | + "g2": GroupMetadata( |
| 513 | + attributes={"key": "g2"}, |
| 514 | + zarr_format=2, |
| 515 | + consolidated_metadata=ConsolidatedMetadata(metadata={}), |
| 516 | + ) |
| 517 | + } |
| 518 | + ), |
| 519 | + ), |
| 520 | + } |
| 521 | + ), |
| 522 | + ) |
| 523 | + assert result.metadata == expected |
0 commit comments