Skip to content

Commit 94294dc

Browse files
committed
add test for open_like
1 parent cf8c4e3 commit 94294dc

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ async def open_like(
12941294
"""
12951295
like_kwargs = _like_args(a) | kwargs
12961296
if isinstance(a, (AsyncArray | Array)):
1297-
kwargs.setdefault("fill_value", a.metadata.fill_value)
1297+
like_kwargs.setdefault("fill_value", a.metadata.fill_value)
12981298
return await open_array(path=path, **like_kwargs) # type: ignore[arg-type]
12991299

13001300

tests/test_api.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, get_args
44

55
if TYPE_CHECKING:
66
import pathlib
@@ -68,13 +68,16 @@ def test_create(memory_store: Store) -> None:
6868
z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True) # type: ignore [arg-type]
6969

7070

71-
@pytest.mark.parametrize("func_name", ["zeros_like", "ones_like", "empty_like", "full_like"])
71+
LikeFuncName = Literal["zeros_like", "ones_like", "empty_like", "full_like", "open_like"]
72+
73+
74+
@pytest.mark.parametrize("func_name", get_args(LikeFuncName))
7275
@pytest.mark.parametrize("out_shape", ["keep", (10, 10)])
7376
@pytest.mark.parametrize("out_chunks", ["keep", (10, 10)])
7477
@pytest.mark.parametrize("out_dtype", ["keep", "int8"])
7578
async def test_array_like_creation(
7679
zarr_format: ZarrFormat,
77-
func_name: str,
80+
func_name: LikeFuncName,
7881
out_shape: Literal["keep"] | tuple[int, ...],
7982
out_chunks: Literal["keep"] | tuple[int, ...],
8083
out_dtype: str,
@@ -101,6 +104,10 @@ async def test_array_like_creation(
101104
elif func_name == "empty_like":
102105
expect_fill = ref_arr.fill_value
103106
func = zarr.api.asynchronous.empty_like
107+
elif func_name == "open_like":
108+
expect_fill = ref_arr.fill_value
109+
kwargs["mode"] = "w"
110+
func = zarr.api.asynchronous.open_like # type: ignore[assignment]
104111
else:
105112
raise AssertionError
106113
if out_shape != "keep":

tests/test_group.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import re
88
import time
99
import warnings
10-
from typing import TYPE_CHECKING, Any, Literal
10+
from typing import TYPE_CHECKING, Any, Literal, get_args
1111

1212
import numpy as np
1313
import pytest
@@ -668,13 +668,16 @@ def test_group_create_array(
668668
assert np.array_equal(array[:], data)
669669

670670

671-
@pytest.mark.parametrize("method_name", ["zeros_like", "ones_like", "empty_like", "full_like"])
671+
LikeMethodName = Literal["zeros_like", "ones_like", "empty_like", "full_like"]
672+
673+
674+
@pytest.mark.parametrize("method_name", get_args(LikeMethodName))
672675
@pytest.mark.parametrize("out_shape", ["keep", (10, 10)])
673676
@pytest.mark.parametrize("out_chunks", ["keep", (10, 10)])
674677
@pytest.mark.parametrize("out_dtype", ["keep", "int8"])
675678
def test_group_array_like_creation(
676679
zarr_format: ZarrFormat,
677-
method_name: str,
680+
method_name: LikeMethodName,
678681
out_shape: Literal["keep"] | tuple[int, ...],
679682
out_chunks: Literal["keep"] | tuple[int, ...],
680683
out_dtype: str,

0 commit comments

Comments
 (0)