Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_save(store: Store, n_args: int, n_kwargs: int) -> None:
assert isinstance(array, Array)
assert_array_equal(array[:], data)
else:
save(store, *args, **kwargs) # type: ignore[arg-type]
save(store, *args, **kwargs) # type: ignore [arg-type]
group = open(store)
assert isinstance(group, Group)
for array in group.array_values():
Expand Down Expand Up @@ -1095,25 +1095,31 @@ async def test_open_falls_back_to_open_group_async() -> None:
assert group.attrs == {"key": "value"}


def test_open_mode_write_creates_group(tmp_path: pathlib.Path) -> None:
@pytest.mark.parametrize("mode", ["r", "r+", "w", "a"])
def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should test this for every store class, but I think that can be a future PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! looking forward to work on it and raise a PR

# https://github.com/zarr-developers/zarr-python/issues/2490
zarr_dir = tmp_path / "test.zarr"
group = zarr.open(zarr_dir, mode="w")
assert isinstance(group, Group)
zarr_dir = tmp_path / f"mode-{mode}-test.zarr"
if mode in ["r", "r+"]:
# Expect FileNotFoundError to be raised if 'r' or 'r+' mode
with pytest.raises(FileNotFoundError):
zarr.open(store=zarr_dir, mode=mode)
else:
group = zarr.open(store=zarr_dir, mode=mode)
assert isinstance(group, Group)


async def test_metadata_validation_error() -> None:
with pytest.raises(
MetadataValidationError,
match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.",
):
await zarr.api.asynchronous.open_group(zarr_format="3.0") # type: ignore[arg-type]
await zarr.api.asynchronous.open_group(zarr_format="3.0") # type: ignore [arg-type]

with pytest.raises(
MetadataValidationError,
match="Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'.",
):
await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") # type: ignore[arg-type]
await zarr.api.asynchronous.open_array(shape=(1,), zarr_format="3.0") # type: ignore [arg-type]


@pytest.mark.parametrize(
Expand Down