Skip to content

Commit

Permalink
Merge pull request #33 from braingram/to_internal_tests
Browse files Browse the repository at this point in the history
Add another unit test, remove unused `reserve_blocks`
  • Loading branch information
braingram authored Oct 17, 2023
2 parents 8440041 + 842f712 commit eab894e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 0 additions & 10 deletions asdf_zarr/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,3 @@ def from_yaml_tree(self, node, tag, ctx):
# TODO mode, version, path_str?
obj = zarr.open(store=store, chunk_store=chunk_store)
return obj

def reserve_blocks(self, obj, tag):
if not isinstance(obj.chunk_store, storage.InternalStore):
return []

# if this block uses a 'InternalStore' it uses blocks
keys = list(obj.chunk_store._chunk_asdf_keys.keys())
if obj.chunk_store._chunk_block_map_asdf_key is not None:
keys.append(obj._chunk_block_map_asdf_key)
return keys
16 changes: 16 additions & 0 deletions asdf_zarr/tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,19 @@ def test_open_mode(tmp_path, mode):
af["arr"][0, 0] = 1
else:
raise Exception(f"Unknown mode {mode}")


@pytest.mark.parametrize("meta_store", [True, False])
def test_to_internal(meta_store):
if meta_store:
zarr = create_zarray(store=KVStore({}), chunk_store=TempStore())
else:
zarr = create_zarray(store=TempStore())
internal = asdf_zarr.storage.to_internal(zarr)
assert isinstance(internal.chunk_store, asdf_zarr.storage.InternalStore)
# the store shouldn't be wrapped if it's not used for chunks
if zarr.store is not zarr.chunk_store:
assert isinstance(internal.store, KVStore)
# calling it a second time shouldn't re-wrap the store
same = asdf_zarr.storage.to_internal(internal)
assert same.chunk_store is internal.chunk_store

0 comments on commit eab894e

Please sign in to comment.