-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bde3d7f
commit d1a2c96
Showing
4 changed files
with
128 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from pathlib import Path | ||
|
||
import zarr | ||
import zarr.store | ||
from pytest import fixture | ||
|
||
|
||
def _create_zarr(tempdir, zarr_format=2): | ||
zarr_path = Path(tempdir) / f"test_group_v{2}.zarr" | ||
group = zarr.open_group(store=zarr_path, mode="w", zarr_format=zarr_format) | ||
|
||
for i in range(3): | ||
group.create_array(f"array_{i}", shape=(10, 10), dtype="i4") | ||
|
||
for i in range(3): | ||
group.create_group(f"group_{i}") | ||
|
||
return zarr_path | ||
|
||
|
||
@fixture | ||
def local_zarr_path_v2(tmpdir) -> tuple[Path, int]: | ||
zarr_path = _create_zarr(tmpdir, zarr_format=2) | ||
return zarr_path, 2 | ||
|
||
|
||
@fixture | ||
def local_zarr_path_v3(tmpdir) -> tuple[Path, int]: | ||
zarr_path = _create_zarr(tmpdir, zarr_format=3) | ||
return zarr_path, 3 | ||
|
||
|
||
@fixture( | ||
params=[ | ||
"local_zarr_path_v2", | ||
"local_zarr_path_v3", | ||
] | ||
) | ||
def store_fixture(request): | ||
return request.getfixturevalue(request.param) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class TestGroupUtils: | ||
@property | ||
def test_attrs(self) -> dict: | ||
return {"a": 1, "b": 2, "c": 3} | ||
|
||
def test_update_group_attrs(self, store_fixture): | ||
from ngio.io.zarr_group_utils import ( | ||
read_group_attrs, | ||
update_group_attrs, | ||
) | ||
|
||
store, zarr_format = store_fixture | ||
|
||
update_group_attrs(store=store, attrs=self.test_attrs, zarr_format=zarr_format) | ||
attrs = read_group_attrs(store=store, zarr_format=zarr_format) | ||
assert attrs == self.test_attrs, "Attributes were not written correctly." | ||
|
||
update_group_attrs(store=store, attrs={"new": 1}, zarr_format=zarr_format) | ||
attrs = read_group_attrs(store=store, zarr_format=zarr_format) | ||
expected = {**self.test_attrs, "new": 1} | ||
assert attrs == expected, "Attributes were not written correctly." | ||
|
||
def test_overwrite_group_attrs(self, store_fixture): | ||
from ngio.io.zarr_group_utils import ( | ||
overwrite_group_attrs, | ||
read_group_attrs, | ||
) | ||
|
||
store, zarr_format = store_fixture | ||
|
||
overwrite_group_attrs( | ||
store=store, attrs=self.test_attrs, zarr_format=zarr_format | ||
) | ||
attrs = read_group_attrs(store=store, zarr_format=zarr_format) | ||
assert attrs == self.test_attrs, "Attributes were not written correctly." | ||
|
||
def test_list_group_arrays(self, store_fixture): | ||
from ngio.io.zarr_group_utils import list_group_arrays | ||
|
||
store, zarr_format = store_fixture | ||
|
||
arrays = list_group_arrays(store=store, zarr_format=zarr_format) | ||
assert len(arrays) == 3, "Arrays were not listed correctly." | ||
|
||
def test_list_group_groups(self, store_fixture): | ||
from ngio.io.zarr_group_utils import list_group_groups | ||
|
||
store, zarr_format = store_fixture | ||
|
||
groups = list_group_groups(store=store, zarr_format=zarr_format) | ||
assert len(groups) == 3, "Groups were not listed correctly." |