|
1 | 1 | import array
|
2 | 2 | import atexit
|
| 3 | +import copy |
3 | 4 | import os
|
4 | 5 | import tempfile
|
5 | 6 |
|
6 | 7 | import numpy as np
|
7 | 8 | import pytest
|
| 9 | +from zarr._storage.store import _get_hierarchy_metadata |
| 10 | +from zarr.meta import _default_entry_point_metadata_v3 |
8 | 11 | from zarr.storage import (ABSStoreV3, ConsolidatedMetadataStoreV3, DBMStoreV3,
|
9 | 12 | DirectoryStoreV3, FSStoreV3, KVStore, KVStoreV3,
|
10 | 13 | LMDBStoreV3, LRUStoreCacheV3, MemoryStoreV3,
|
@@ -485,3 +488,26 @@ def metadata_key(self):
|
485 | 488 | def test_bad_store_version(self):
|
486 | 489 | with pytest.raises(ValueError):
|
487 | 490 | 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