Skip to content

Commit e60cbe0

Browse files
committed
add nchunks test
1 parent df6f9a7 commit e60cbe0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/v3/test_array.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import numpy as np
66
import pytest
77

8-
from src.zarr.core.array import chunks_initialized
98
from zarr import Array, AsyncArray, Group
9+
from zarr.core.array import chunks_initialized
1010
from zarr.core.buffer.cpu import NDBuffer
1111
from zarr.core.common import ZarrFormat
12+
from zarr.core.indexing import ceildiv
1213
from zarr.core.sync import sync
1314
from zarr.errors import ContainsArrayError, ContainsGroupError
1415
from zarr.store import LocalStore, MemoryStore
@@ -237,6 +238,23 @@ def test_serializable_sync_array(store: LocalStore, zarr_format: ZarrFormat) ->
237238
np.testing.assert_array_equal(actual[:], expected[:])
238239

239240

241+
@pytest.mark.parametrize("test_cls", [Array, AsyncArray])
242+
@pytest.mark.parametrize("nchunks", (2, 5, 10))
243+
def test_nchunks(test_cls: type[Array] | type[AsyncArray], nchunks: int) -> None:
244+
"""
245+
Test that nchunks returns the number of chunks defined for the array.
246+
"""
247+
store = MemoryStore({}, mode="w")
248+
shape = 100
249+
arr = Array.create(store, shape=(shape,), chunks=(ceildiv(shape, nchunks),), dtype="i4")
250+
expected = nchunks
251+
if test_cls == Array:
252+
observed = arr.nchunks
253+
else:
254+
observed = arr._async_array.nchunks
255+
assert observed == expected
256+
257+
240258
@pytest.mark.parametrize("test_cls", [Array, AsyncArray])
241259
def test_nchunks_initialized(test_cls: type[Array] | type[AsyncArray]) -> None:
242260
"""

0 commit comments

Comments
 (0)