Skip to content

Commit 58f05fe

Browse files
committed
improve tests
1 parent 092a1e0 commit 58f05fe

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

tests/test_array.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import numcodecs
1010
import numpy as np
11+
import numpy.typing as npt
1112
import pytest
1213

1314
import zarr.api.asynchronous
@@ -1299,8 +1300,8 @@ async def test_creation_from_other_zarr_format(
12991300

13001301
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True)
13011302
@pytest.mark.parametrize("store2", ["local", "memory", "zip"], indirect=["store2"])
1302-
@pytest.mark.parametrize("src_chunks", [(10, 2), (50, 10)])
1303-
@pytest.mark.parametrize("new_chunks", [(10, 2), (50, 10)])
1303+
@pytest.mark.parametrize("src_chunks", [(40, 10), (11, 50)])
1304+
@pytest.mark.parametrize("new_chunks", [(40, 10), (11, 50)])
13041305
async def test_from_array(
13051306
store: Store,
13061307
store2: Store,
@@ -1340,11 +1341,30 @@ async def test_from_array(
13401341
assert result.chunks == new_chunks
13411342

13421343

1343-
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True)
1344-
@pytest.mark.parametrize("chunks", [(10, 2, 3), "keep", "auto"])
1345-
async def test_from_numpy_array(
1346-
store: Store, chunks: Literal["auto", "keep"] | tuple[int, int]
1344+
@pytest.mark.parametrize("store", ["local"], indirect=True)
1345+
@pytest.mark.parametrize("chunks", ["keep", "auto"])
1346+
@pytest.mark.parametrize("write_data", [True, False])
1347+
@pytest.mark.parametrize(
1348+
"src",
1349+
[
1350+
np.arange(1000).reshape(10, 10, 10),
1351+
zarr.ones((10, 10, 10)),
1352+
5,
1353+
[1, 2, 3],
1354+
[[1, 2, 3], [4, 5, 6]],
1355+
],
1356+
) # add other npt.ArrayLike?
1357+
async def test_from_array_arraylike(
1358+
store: Store,
1359+
chunks: Literal["auto", "keep"] | tuple[int, int],
1360+
write_data: bool,
1361+
src: Array | npt.ArrayLike,
13471362
) -> None:
1348-
src = np.arange(1000).reshape(10, 10, 10)
1349-
result = zarr.from_array(src, store=store, chunks=chunks)
1350-
np.testing.assert_array_equal(result[:], src)
1363+
fill_value = 42
1364+
result = zarr.from_array(
1365+
src, store=store, chunks=chunks, write_data=write_data, fill_value=fill_value
1366+
)
1367+
if write_data:
1368+
np.testing.assert_array_equal(result[...], src)
1369+
else:
1370+
np.testing.assert_array_equal(result[...], np.full_like(src, fill_value))

0 commit comments

Comments
 (0)