Skip to content

Commit 2afe940

Browse files
committed
tests
1 parent ff5e5cb commit 2afe940

File tree

3 files changed

+39
-47
lines changed

3 files changed

+39
-47
lines changed

tests/test_codecs/test_codecs.py

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ async def test_order(
7878
path = "order"
7979
spath = StorePath(store, path=path)
8080

81-
with config.set({"array.order": runtime_write_order}):
82-
a = await zarr.api.asynchronous.create_array(
83-
spath,
84-
shape=data.shape,
85-
chunks=(16, 8) if with_sharding else (32, 8),
86-
shards=(32, 8) if with_sharding else None,
87-
dtype=data.dtype,
88-
fill_value=0,
89-
chunk_key_encoding={"name": "v2", "separator": "."},
90-
filters=[TransposeCodec(order=order_from_dim(store_order, data.ndim))],
91-
)
81+
a = await zarr.api.asynchronous.create_array(
82+
spath,
83+
shape=data.shape,
84+
chunks=(16, 8) if with_sharding else (32, 8),
85+
shards=(32, 8) if with_sharding else None,
86+
dtype=data.dtype,
87+
fill_value=0,
88+
chunk_key_encoding={"name": "v2", "separator": "."},
89+
filters=[TransposeCodec(order=order_from_dim(store_order, data.ndim))],
90+
config={"order": runtime_write_order},
91+
)
9292

9393
await _AsyncArrayProxy(a)[:, :].set(data)
9494
read_data = await _AsyncArrayProxy(a)[:, :].get()
@@ -364,42 +364,10 @@ def test_invalid_metadata(store: Store) -> None:
364364

365365
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
366366
def test_invalid_metadata_create_array(store: Store) -> None:
367-
spath3 = StorePath(store, "invalid_order")
368-
with pytest.raises(TypeError):
369-
zarr.create_array(
370-
spath3,
371-
shape=(16, 16),
372-
chunks=(16, 16),
373-
dtype=np.dtype("uint8"),
374-
fill_value=0,
375-
filters=[
376-
TransposeCodec(order="F"), # type: ignore[arg-type]
377-
],
378-
)
379-
spath5 = StorePath(store, "invalid_inner_chunk_shape")
380-
with pytest.raises(ValueError):
381-
zarr.create_array(
382-
spath5,
383-
shape=(16, 16),
384-
shards=(16, 16),
385-
chunks=(8,),
386-
dtype=np.dtype("uint8"),
387-
fill_value=0,
388-
)
389-
spath6 = StorePath(store, "invalid_inner_chunk_shape")
390-
with pytest.raises(ValueError):
391-
zarr.create_array(
392-
spath6,
393-
shape=(16, 16),
394-
shards=(16, 16),
395-
chunks=(8, 7),
396-
dtype=np.dtype("uint8"),
397-
fill_value=0,
398-
)
399-
spath7 = StorePath(store, "warning_inefficient_codecs")
367+
spath = StorePath(store, "warning_inefficient_codecs")
400368
with pytest.warns(UserWarning):
401369
zarr.create_array(
402-
spath7,
370+
spath,
403371
shape=(16, 16),
404372
chunks=(16, 16),
405373
dtype=np.dtype("uint8"),

tests/test_codecs/test_sharding.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,27 @@ async def test_sharding_with_chunks_per_shard(
424424
a[...] = data
425425
data_read = a[...]
426426
assert np.array_equal(data_read, data)
427+
428+
429+
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
430+
def test_invalid_metadata(store: Store) -> None:
431+
spath1 = StorePath(store, "invalid_inner_chunk_shape")
432+
with pytest.raises(ValueError):
433+
zarr.create_array(
434+
spath1,
435+
shape=(16, 16),
436+
shards=(16, 16),
437+
chunks=(8,),
438+
dtype=np.dtype("uint8"),
439+
fill_value=0,
440+
)
441+
spath2 = StorePath(store, "invalid_inner_chunk_shape")
442+
with pytest.raises(ValueError):
443+
zarr.create_array(
444+
spath2,
445+
shape=(16, 16),
446+
shards=(16, 16),
447+
chunks=(8, 7),
448+
dtype=np.dtype("uint8"),
449+
fill_value=0,
450+
)

tests/test_codecs/test_transpose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def test_transpose_invalid(
8181
) -> None:
8282
data = np.arange(0, 256, dtype="uint16").reshape((1, 32, 8))
8383
spath = StorePath(store, "transpose_invalid")
84-
for order in [(1, 0), (3, 2, 1), (3, 3, 1)]:
85-
with pytest.raises(ValueError):
84+
for order in [(1, 0), (3, 2, 1), (3, 3, 1), "F", "C"]:
85+
with pytest.raises((ValueError, TypeError)):
8686
zarr.create_array(
8787
spath,
8888
shape=data.shape,

0 commit comments

Comments
 (0)