Skip to content

Commit d29f682

Browse files
committed
add test cases for fill_value in test_array_like_creation
1 parent 19b1ce2 commit d29f682

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

tests/test_api.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,52 @@ def test_create(memory_store: Store) -> None:
9090
@pytest.mark.parametrize("out_shape", ["keep", (10, 10)])
9191
@pytest.mark.parametrize("out_chunks", ["keep", (10, 10)])
9292
@pytest.mark.parametrize("out_dtype", ["keep", "int8"])
93+
@pytest.mark.parametrize("out_fill", ["keep", 4])
9394
async def test_array_like_creation(
9495
zarr_format: ZarrFormat,
9596
func: Callable[[Any], Any],
9697
out_shape: Literal["keep"] | tuple[int, ...],
9798
out_chunks: Literal["keep"] | tuple[int, ...],
9899
out_dtype: str,
100+
out_fill: Literal["keep"] | int,
99101
) -> None:
100102
"""
101103
Test zeros_like, ones_like, empty_like, full_like, ensuring that we can override the
102-
shape, chunks, and dtype of the array-like object provided to these functions with
104+
shape, chunks, dtype and fill_value of the array-like object provided to these functions with
103105
appropriate keyword arguments
104106
"""
105-
ref_arr = zarr.ones(
106-
store={}, shape=(11, 12), dtype="uint8", chunks=(11, 12), zarr_format=zarr_format
107+
ref_fill = 100
108+
ref_arr = zarr.create_array(
109+
store={},
110+
shape=(11, 12),
111+
dtype="uint8",
112+
chunks=(11, 12),
113+
zarr_format=zarr_format,
114+
fill_value=ref_fill,
107115
)
108116
kwargs: dict[str, object] = {}
109117
if func is zarr.api.asynchronous.full_like:
110-
expect_fill = 4
111-
kwargs["fill_value"] = expect_fill
118+
if out_fill == "keep":
119+
expect_fill = ref_fill
120+
else:
121+
expect_fill = out_fill
122+
kwargs["fill_value"] = expect_fill
112123
elif func is zarr.api.asynchronous.zeros_like:
113124
expect_fill = 0
114125
elif func is zarr.api.asynchronous.ones_like:
115126
expect_fill = 1
116127
elif func is zarr.api.asynchronous.empty_like:
117-
expect_fill = ref_arr.fill_value
128+
if out_fill == "keep":
129+
expect_fill = ref_fill
130+
else:
131+
kwargs["fill_value"] = out_fill
132+
expect_fill = out_fill
118133
elif func is zarr.api.asynchronous.open_like: # type: ignore[assignment]
119-
expect_fill = ref_arr.fill_value
134+
if out_fill == "keep":
135+
expect_fill = ref_fill
136+
else:
137+
kwargs["fill_value"] = out_fill
138+
expect_fill = out_fill
120139
kwargs["mode"] = "w"
121140
else:
122141
raise AssertionError

0 commit comments

Comments
 (0)