Skip to content

Commit 7aa5dff

Browse files
committed
add test_get_hierarchy_metadata to test the v3 _get_hierarchy_metadata helper
1 parent 2b82967 commit 7aa5dff

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

zarr/tests/test_storage_v3.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import array
22
import atexit
3+
import copy
34
import os
45
import tempfile
56

67
import numpy as np
78
import pytest
9+
from zarr._storage.store import _get_hierarchy_metadata
10+
from zarr.meta import _default_entry_point_metadata_v3
811
from zarr.storage import (ABSStoreV3, ConsolidatedMetadataStoreV3, DBMStoreV3,
912
DirectoryStoreV3, FSStoreV3, KVStore, KVStoreV3,
1013
LMDBStoreV3, LRUStoreCacheV3, MemoryStoreV3,
@@ -485,3 +488,26 @@ def metadata_key(self):
485488
def test_bad_store_version(self):
486489
with pytest.raises(ValueError):
487490
self.ConsolidatedMetadataClass(KVStore(dict()))
491+
492+
493+
def test_get_hierarchy_metadata():
494+
store = KVStoreV3({})
495+
496+
# error raised if 'jarr.json' is not in the store
497+
with pytest.raises(ValueError):
498+
_get_hierarchy_metadata(store)
499+
500+
store['zarr.json'] = _default_entry_point_metadata_v3
501+
assert _get_hierarchy_metadata(store) == _default_entry_point_metadata_v3
502+
503+
# ValueError if only a subset of keys are present
504+
store['zarr.json'] = {'zarr_format': 'https://purl.org/zarr/spec/protocol/core/3.0'}
505+
with pytest.raises(ValueError):
506+
_get_hierarchy_metadata(store)
507+
508+
# ValueError if any unexpected keys are present
509+
extra_metadata = copy.copy(_default_entry_point_metadata_v3)
510+
extra_metadata['extra_key'] = 'value'
511+
store['zarr.json'] = extra_metadata
512+
with pytest.raises(ValueError):
513+
_get_hierarchy_metadata(store)

0 commit comments

Comments
 (0)