|
13 | 13 | from zarr.abc.store import Store |
14 | 14 | from zarr.core.buffer import default_buffer_prototype |
15 | 15 | from zarr.core.common import JSON, ZarrFormat |
16 | | -from zarr.core.group import ConsolidatedMetadata, GroupMetadata |
| 16 | +from zarr.core.group import ConsolidatedMetadata, GroupMetadata, _MixedConsolidatedMetadataException |
17 | 17 | from zarr.core.sync import sync |
18 | 18 | from zarr.errors import ContainsArrayError, ContainsGroupError |
19 | 19 | from zarr.storage import LocalStore, MemoryStore, StorePath, ZipStore |
@@ -316,15 +316,37 @@ def test_group_getitem(store: Store, zarr_format: ZarrFormat, consolidated: bool |
316 | 316 |
|
317 | 317 | assert group["subgroup"] == subgroup |
318 | 318 | assert group["subarray"] == subarray |
319 | | - assert subgroup["subarray"] == subsubarray |
320 | | - # assert group["subgroup/subarray"] == subsubarray |
| 319 | + assert group["subgroup"]["subarray"] == subsubarray |
| 320 | + assert group["subgroup/subarray"] == subsubarray |
321 | 321 |
|
322 | 322 | with pytest.raises(KeyError): |
323 | 323 | group["nope"] |
324 | 324 |
|
325 | 325 | with pytest.raises(KeyError, match="subarray/subsubarray"): |
326 | 326 | group["subarray/subsubarray"] |
327 | 327 |
|
| 328 | + # Now test the mixed case |
| 329 | + if consolidated: |
| 330 | + group = zarr.api.synchronous.consolidate_metadata(store=store, zarr_format=zarr_format) |
| 331 | + # we're going to assume that `group.metadata` is correct, and reuse that to focus |
| 332 | + # on indexing in this test. Other tests verify the correctness of group.metadata |
| 333 | + object.__setattr__( |
| 334 | + group.metadata.consolidated_metadata.metadata["subgroup"], |
| 335 | + "consolidated_metadata", |
| 336 | + None, |
| 337 | + ) |
| 338 | + |
| 339 | + # test the implementation directly |
| 340 | + with pytest.raises(_MixedConsolidatedMetadataException): |
| 341 | + group._async_group._getitem_consolidated( |
| 342 | + group.store_path, "subgroup/subarray", prefix="/" |
| 343 | + ) |
| 344 | + |
| 345 | + assert group["subgroup/subarray"] == subsubarray |
| 346 | + |
| 347 | + with pytest.raises(KeyError, match="subarray/subsubarray"): |
| 348 | + group["subarray/subsubarray"] |
| 349 | + |
328 | 350 |
|
329 | 351 | def test_group_get_with_default(store: Store, zarr_format: ZarrFormat) -> None: |
330 | 352 | group = Group.from_store(store, zarr_format=zarr_format) |
|
0 commit comments