def test_migrate_1to2(): from zarr import meta_v1 # N.B., version 1 did not support hierarchies, so we only have to be # concerned about migrating a single array at the root of the store # setup store = dict() meta = dict(shape=(100, ), chunks=(10, ), dtype=np.dtype('f4'), compression='zlib', compression_opts=1, fill_value=None, order='C') meta_json = meta_v1.encode_metadata(meta) store['meta'] = meta_json store['attrs'] = json.dumps(dict()).encode('ascii') # run migration migrate_1to2(store) # check results assert 'meta' not in store assert array_meta_key in store assert 'attrs' not in store assert attrs_key in store meta_migrated = decode_array_metadata(store[array_meta_key]) assert 2 == meta_migrated['zarr_format'] # preserved fields for f in 'shape', 'chunks', 'dtype', 'fill_value', 'order': assert meta[f] == meta_migrated[f] # migrate should have added empty filters field assert meta_migrated['filters'] is None # check compression and compression_opts migrated to compressor assert 'compression' not in meta_migrated assert 'compression_opts' not in meta_migrated assert meta_migrated['compressor'] == Zlib(1).get_config() # check dict compression_opts store = dict() meta['compression'] = 'blosc' meta['compression_opts'] = dict(cname='lz4', clevel=5, shuffle=1) meta_json = meta_v1.encode_metadata(meta) store['meta'] = meta_json store['attrs'] = json.dumps(dict()).encode('ascii') migrate_1to2(store) meta_migrated = decode_array_metadata(store[array_meta_key]) assert 'compression' not in meta_migrated assert 'compression_opts' not in meta_migrated assert (meta_migrated['compressor'] == Blosc(cname='lz4', clevel=5, shuffle=1).get_config()) # check 'none' compression is migrated to None (null in JSON) store = dict() meta['compression'] = 'none' meta_json = meta_v1.encode_metadata(meta) store['meta'] = meta_json store['attrs'] = json.dumps(dict()).encode('ascii') migrate_1to2(store) meta_migrated = decode_array_metadata(store[array_meta_key]) assert 'compression' not in meta_migrated assert 'compression_opts' not in meta_migrated assert meta_migrated['compressor'] is None
def test_migrate_1to2(): from zarr import meta_v1 # N.B., version 1 did not support hierarchies, so we only have to be # concerned about migrating a single array at the root of the store # setup store = dict() meta = dict( shape=(100,), chunks=(10,), dtype=np.dtype('f4'), compression='zlib', compression_opts=1, fill_value=None, order='C' ) meta_json = meta_v1.encode_metadata(meta) store['meta'] = meta_json store['attrs'] = json.dumps(dict()).encode('ascii') # run migration migrate_1to2(store) # check results assert 'meta' not in store assert array_meta_key in store assert 'attrs' not in store assert attrs_key in store meta_migrated = decode_array_metadata(store[array_meta_key]) eq(2, meta_migrated['zarr_format']) # preserved fields for f in 'shape', 'chunks', 'dtype', 'fill_value', 'order': eq(meta[f], meta_migrated[f]) # migrate should have added empty filters field assert_is_none(meta_migrated['filters']) # check compression and compression_opts migrated to compressor assert 'compression' not in meta_migrated assert 'compression_opts' not in meta_migrated eq(meta_migrated['compressor'], Zlib(1).get_config()) # check dict compression_opts store = dict() meta['compression'] = 'blosc' meta['compression_opts'] = dict(cname='lz4', clevel=5, shuffle=1) meta_json = meta_v1.encode_metadata(meta) store['meta'] = meta_json store['attrs'] = json.dumps(dict()).encode('ascii') migrate_1to2(store) meta_migrated = decode_array_metadata(store[array_meta_key]) assert 'compression' not in meta_migrated assert 'compression_opts' not in meta_migrated eq(meta_migrated['compressor'], Blosc(cname='lz4', clevel=5, shuffle=1).get_config()) # check 'none' compression is migrated to None (null in JSON) store = dict() meta['compression'] = 'none' meta_json = meta_v1.encode_metadata(meta) store['meta'] = meta_json store['attrs'] = json.dumps(dict()).encode('ascii') migrate_1to2(store) meta_migrated = decode_array_metadata(store[array_meta_key]) assert 'compression' not in meta_migrated assert 'compression_opts' not in meta_migrated assert_is_none(meta_migrated['compressor'])