Skip to content

Commit

Permalink
add test_get_hierarchy_metadata to test the v3 _get_hierarchy_metadat…
Browse files Browse the repository at this point in the history
…a helper
  • Loading branch information
grlee77 committed Mar 11, 2022
1 parent 2b82967 commit 7aa5dff
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions zarr/tests/test_storage_v3.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import array
import atexit
import copy
import os
import tempfile

import numpy as np
import pytest
from zarr._storage.store import _get_hierarchy_metadata
from zarr.meta import _default_entry_point_metadata_v3
from zarr.storage import (ABSStoreV3, ConsolidatedMetadataStoreV3, DBMStoreV3,
DirectoryStoreV3, FSStoreV3, KVStore, KVStoreV3,
LMDBStoreV3, LRUStoreCacheV3, MemoryStoreV3,
Expand Down Expand Up @@ -485,3 +488,26 @@ def metadata_key(self):
def test_bad_store_version(self):
with pytest.raises(ValueError):
self.ConsolidatedMetadataClass(KVStore(dict()))


def test_get_hierarchy_metadata():
store = KVStoreV3({})

# error raised if 'jarr.json' is not in the store
with pytest.raises(ValueError):
_get_hierarchy_metadata(store)

store['zarr.json'] = _default_entry_point_metadata_v3
assert _get_hierarchy_metadata(store) == _default_entry_point_metadata_v3

# ValueError if only a subset of keys are present
store['zarr.json'] = {'zarr_format': 'https://purl.org/zarr/spec/protocol/core/3.0'}
with pytest.raises(ValueError):
_get_hierarchy_metadata(store)

# ValueError if any unexpected keys are present
extra_metadata = copy.copy(_default_entry_point_metadata_v3)
extra_metadata['extra_key'] = 'value'
store['zarr.json'] = extra_metadata
with pytest.raises(ValueError):
_get_hierarchy_metadata(store)

0 comments on commit 7aa5dff

Please sign in to comment.