Skip to content

Commit 0a18445

Browse files
committed
add test cases
1 parent 5ab9154 commit 0a18445

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

tests/test_api.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,19 @@ def test_create(memory_store: Store) -> None:
7070

7171
# TODO: parametrize over everything this function takes
7272
@pytest.mark.parametrize("store", ["memory"], indirect=True)
73-
def test_create_array(store: Store) -> None:
73+
def test_create_array(store: Store, zarr_format: ZarrFormat) -> None:
7474
attrs: dict[str, JSON] = {"foo": 100} # explicit type annotation to avoid mypy error
7575
shape = (10, 10)
7676
path = "foo"
7777
data_val = 1
7878
array_w = create_array(
79-
store, name=path, shape=shape, attributes=attrs, chunks=shape, dtype="uint8"
79+
store,
80+
name=path,
81+
shape=shape,
82+
attributes=attrs,
83+
chunks=shape,
84+
dtype="uint8",
85+
zarr_format=zarr_format,
8086
)
8187
array_w[:] = data_val
8288
assert array_w.shape == shape
@@ -85,18 +91,27 @@ def test_create_array(store: Store) -> None:
8591

8692

8793
@pytest.mark.parametrize("write_empty_chunks", [True, False])
88-
def test_write_empty_chunks_warns(write_empty_chunks: bool) -> None:
94+
def test_write_empty_chunks_warns(write_empty_chunks: bool, zarr_format: ZarrFormat) -> None:
8995
"""
9096
Test that using the `write_empty_chunks` kwarg on array access will raise a warning.
9197
"""
9298
match = "The `write_empty_chunks` keyword argument .*"
9399
with pytest.warns(RuntimeWarning, match=match):
94100
_ = zarr.array(
95-
data=np.arange(10), shape=(10,), dtype="uint8", write_empty_chunks=write_empty_chunks
101+
data=np.arange(10),
102+
shape=(10,),
103+
dtype="uint8",
104+
write_empty_chunks=write_empty_chunks,
105+
zarr_format=zarr_format,
96106
)
97107

98108
with pytest.warns(RuntimeWarning, match=match):
99-
_ = zarr.create(shape=(10,), dtype="uint8", write_empty_chunks=write_empty_chunks)
109+
_ = zarr.create(
110+
shape=(10,),
111+
dtype="uint8",
112+
write_empty_chunks=write_empty_chunks,
113+
zarr_format=zarr_format,
114+
)
100115

101116

102117
@pytest.mark.parametrize("path", ["foo", "/", "/foo", "///foo/bar"])
@@ -113,18 +128,18 @@ def test_open_normalized_path(
113128
assert node.path == normalize_path(path)
114129

115130

116-
async def test_open_array(memory_store: MemoryStore) -> None:
131+
async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) -> None:
117132
store = memory_store
118133

119134
# open array, create if doesn't exist
120-
z = open(store=store, shape=100)
135+
z = open(store=store, shape=100, zarr_format=zarr_format)
121136
assert isinstance(z, Array)
122137
assert z.shape == (100,)
123138

124139
# open array, overwrite
125140
# store._store_dict = {}
126141
store = MemoryStore()
127-
z = open(store=store, shape=200)
142+
z = open(store=store, shape=200, zarr_format=zarr_format)
128143
assert isinstance(z, Array)
129144
assert z.shape == (200,)
130145

@@ -138,7 +153,7 @@ async def test_open_array(memory_store: MemoryStore) -> None:
138153

139154
# path not found
140155
with pytest.raises(FileNotFoundError):
141-
open(store="doesnotexist", mode="r")
156+
open(store="doesnotexist", mode="r", zarr_format=zarr_format)
142157

143158

144159
@pytest.mark.parametrize("store", ["memory"], indirect=True)
@@ -161,9 +176,9 @@ async def test_open_group(memory_store: MemoryStore) -> None:
161176
assert "foo" in g
162177

163178
# open group, overwrite
164-
# g = open_group(store=store)
165-
# assert isinstance(g, Group)
166-
# assert "foo" not in g
179+
g = open_group(store=store, mode="w")
180+
assert isinstance(g, Group)
181+
assert "foo" not in g
167182

168183
# open group, read-only
169184
store_cls = type(store)
@@ -306,7 +321,6 @@ def test_open_with_mode_w_minus(tmp_path: pathlib.Path) -> None:
306321
zarr.open(store=tmp_path, mode="w-")
307322

308323

309-
@pytest.mark.parametrize("zarr_format", [2, 3])
310324
def test_array_order(zarr_format: ZarrFormat) -> None:
311325
arr = zarr.ones(shape=(2, 2), order=None, zarr_format=zarr_format)
312326
expected = zarr.config.get("array.order")
@@ -322,7 +336,6 @@ def test_array_order(zarr_format: ZarrFormat) -> None:
322336

323337

324338
@pytest.mark.parametrize("order", ["C", "F"])
325-
@pytest.mark.parametrize("zarr_format", [2, 3])
326339
def test_array_order_warns(order: MemoryOrder | None, zarr_format: ZarrFormat) -> None:
327340
with pytest.warns(RuntimeWarning, match="The `order` keyword argument .*"):
328341
arr = zarr.ones(shape=(2, 2), order=order, zarr_format=zarr_format)
@@ -1135,13 +1148,14 @@ async def test_metadata_validation_error() -> None:
11351148
["local", "memory", "zip"],
11361149
indirect=True,
11371150
)
1138-
def test_open_array_with_mode_r_plus(store: Store) -> None:
1151+
def test_open_array_with_mode_r_plus(store: Store, zarr_format: ZarrFormat) -> None:
11391152
# 'r+' means read/write (must exist)
11401153
with pytest.raises(FileNotFoundError):
1141-
zarr.open_array(store=store, mode="r+")
1142-
zarr.ones(store=store, shape=(3, 3))
1154+
zarr.open_array(store=store, mode="r+", zarr_format=zarr_format)
1155+
zarr.ones(store=store, shape=(3, 3), zarr_format=zarr_format)
11431156
z2 = zarr.open_array(store=store, mode="r+")
11441157
assert isinstance(z2, Array)
1158+
assert z2.metadata.zarr_format == zarr_format
11451159
result = z2[:]
11461160
assert isinstance(result, NDArrayLike)
11471161
assert (result == 1).all()

tests/test_array.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str
227227
assert arr.fill_value.dtype == arr.dtype
228228

229229

230-
def test_create_positional_args_deprecated() -> None:
231-
store = MemoryStore()
232-
with pytest.warns(FutureWarning, match="Pass"):
233-
zarr.Array.create(store, (2, 2), dtype="f8")
230+
async def test_create_deprecated() -> None:
231+
with pytest.warns(DeprecationWarning):
232+
with pytest.warns(FutureWarning, match="Pass"):
233+
await zarr.AsyncArray.create(MemoryStore(), (2, 2), dtype="f8")
234+
with pytest.warns(DeprecationWarning):
235+
with pytest.warns(FutureWarning, match="Pass"):
236+
zarr.Array.create(MemoryStore(), (2, 2), dtype="f8")
234237

235238

236239
def test_selection_positional_args_deprecated() -> None:

0 commit comments

Comments
 (0)