Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman committed Jun 1, 2024
1 parent 9ab393e commit deaa264
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/zarr/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,15 @@ def create(
store: StoreLike,
*,
attributes: dict[str, Any] = {}, # noqa: B006, FIXME
zarr_format: ZarrFormat = 3,
exists_ok: bool = False,
) -> Group:
obj = sync(
AsyncGroup.create(
store,
attributes=attributes,
exists_ok=exists_ok,
zarr_format=zarr_format,
),
)

Expand Down
36 changes: 36 additions & 0 deletions tests/v3/test_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from zarr.array import Array
from zarr.common import ZarrFormat
from zarr.group import Group
from zarr.store import LocalStore, MemoryStore


@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
def test_array_name_properties_no_group(
store: LocalStore | MemoryStore, zarr_format: ZarrFormat
) -> None:
arr = Array.create(store=store, shape=(100,), chunks=(10,), zarr_format=zarr_format, dtype="i4")
assert arr.path == ""
assert arr.name is None
assert arr.basename is None


@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
def test_array_name_properties_with_group(
store: LocalStore | MemoryStore, zarr_format: ZarrFormat
) -> None:
root = Group.create(store=store, zarr_format=zarr_format)
foo = root.create_array("foo", shape=(100,), chunks=(10,), dtype="i4")
assert foo.path == "foo"
assert foo.name == "/foo"
assert foo.basename == "foo"

bar = root.create_group("bar")
spam = bar.create_array("spam", shape=(100,), chunks=(10,), dtype="i4")

assert spam.path == "bar/spam"
assert spam.name == "/bar/spam"
assert spam.basename == "spam"
19 changes: 19 additions & 0 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,22 @@ async def test_group_init(store: LocalStore | MemoryStore, zarr_format: ZarrForm
agroup = sync(AsyncGroup.create(store=store, zarr_format=zarr_format))
group = Group(agroup)
assert group._async_group == agroup


@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
def test_group_name_properties(store: LocalStore | MemoryStore, zarr_format: ZarrFormat) -> None:
root = Group.create(store=store, zarr_format=zarr_format)
assert root.path == ""
assert root.name == "/"
assert root.basename == ""

foo = root.create_group("foo")
assert foo.path == "foo"
assert foo.name == "/foo"
assert foo.basename == "foo"

bar = root.create_group("foo/bar")
assert bar.path == "foo/bar"
assert bar.name == "/foo/bar"
assert bar.basename == "bar"

0 comments on commit deaa264

Please sign in to comment.