Skip to content

Commit 892470f

Browse files
committed
add basic tests for reading and writing to ConsolidatedMetadataStore
1 parent f304350 commit 892470f

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

zarr/tests/test_storage.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,11 +1257,44 @@ def test_format_compatibility():
12571257
class TestConsolidatedMetadataStore(unittest.TestCase):
12581258

12591259
def test_bad_format(self):
1260+
1261+
# setup store with consolidated metdata
12601262
store = dict()
1261-
metadata = json.dumps({
1263+
consolidated = {
12621264
# bad format version
12631265
'zarr_consolidated_format': 0,
1264-
})
1265-
store['.zmetadata'] = metadata
1266+
}
1267+
store['.zmetadata'] = json.dumps(consolidated)
1268+
1269+
# check appropriate error is raised
12661270
with pytest.raises(MetadataError):
12671271
ConsolidatedMetadataStore(store)
1272+
1273+
def test_read_write(self):
1274+
1275+
# setup store with consolidated metdata
1276+
store = dict()
1277+
consolidated = {
1278+
'zarr_consolidated_format': 1,
1279+
'metadata': {
1280+
'foo': 'bar',
1281+
'baz': 42,
1282+
}
1283+
}
1284+
store['.zmetadata'] = json.dumps(consolidated)
1285+
1286+
# create consolidated store
1287+
cs = ConsolidatedMetadataStore(store)
1288+
1289+
# test __contains__, __getitem__
1290+
for key, value in consolidated['metadata'].items():
1291+
assert key in cs
1292+
assert value == cs[key]
1293+
1294+
# test __delitem__, __setitem__
1295+
with pytest.raises(PermissionError):
1296+
del cs['foo']
1297+
with pytest.raises(PermissionError):
1298+
cs['bar'] = 0
1299+
with pytest.raises(PermissionError):
1300+
cs['spam'] = 'eggs'

0 commit comments

Comments
 (0)