@@ -1257,11 +1257,44 @@ def test_format_compatibility():
1257
1257
class TestConsolidatedMetadataStore (unittest .TestCase ):
1258
1258
1259
1259
def test_bad_format (self ):
1260
+
1261
+ # setup store with consolidated metdata
1260
1262
store = dict ()
1261
- metadata = json . dumps ( {
1263
+ consolidated = {
1262
1264
# bad format version
1263
1265
'zarr_consolidated_format' : 0 ,
1264
- })
1265
- store ['.zmetadata' ] = metadata
1266
+ }
1267
+ store ['.zmetadata' ] = json .dumps (consolidated )
1268
+
1269
+ # check appropriate error is raised
1266
1270
with pytest .raises (MetadataError ):
1267
1271
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