Skip to content

Commit 64f25f3

Browse files
committed
test: update tests
1 parent a306e72 commit 64f25f3

1 file changed

Lines changed: 18 additions & 50 deletions

File tree

tests/test_sync_codec_pipeline.py

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
from zarr.core.dtype import get_data_type_from_native_dtype
1818

1919

20+
class AsyncOnlyCodec(ArrayBytesCodec): # type: ignore[misc]
21+
"""A codec that only supports async, for testing rejection of non-sync codecs."""
22+
23+
is_fixed_size = True
24+
25+
async def _decode_single(self, chunk_data: Buffer, chunk_spec: ArraySpec) -> NDBuffer:
26+
raise NotImplementedError # pragma: no cover
27+
28+
async def _encode_single(self, chunk_data: NDBuffer, chunk_spec: ArraySpec) -> Buffer | None:
29+
raise NotImplementedError # pragma: no cover
30+
31+
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
32+
return input_byte_length # pragma: no cover
33+
34+
2035
def _make_array_spec(shape: tuple[int, ...], dtype: np.dtype[np.generic]) -> ArraySpec:
2136
zdtype = get_data_type_from_native_dtype(dtype)
2237
return ArraySpec(
@@ -63,22 +78,6 @@ def test_encode_decode_roundtrip_bytes_only(self) -> None:
6378
decoded = chain.decode(encoded)
6479
np.testing.assert_array_equal(arr, decoded.as_numpy_array())
6580

66-
def test_shape_dtype_no_aa_codecs(self) -> None:
67-
# Without AA codecs, shape and dtype should match the input ArraySpec
68-
# (no transforms applied before the AB codec).
69-
spec = _make_array_spec((100,), np.dtype("float64"))
70-
chunk = ChunkTransform(codecs=(BytesCodec(),), array_spec=spec)
71-
assert chunk.shape == (100,)
72-
assert chunk.dtype == spec.dtype
73-
74-
def test_shape_dtype_with_transpose(self) -> None:
75-
# TransposeCodec(order=(1,0)) on a (3, 4) array produces (4, 3).
76-
# shape/dtype reflect what the AB codec sees after all AA transforms.
77-
spec = _make_array_spec((3, 4), np.dtype("float64"))
78-
chunk = ChunkTransform(codecs=(TransposeCodec(order=(1, 0)), BytesCodec()), array_spec=spec)
79-
assert chunk.shape == (4, 3)
80-
assert chunk.dtype == spec.dtype
81-
8281
def test_encode_decode_roundtrip_with_compression(self) -> None:
8382
# Round-trip with a BB codec (GzipCodec) to verify that bytes-bytes
8483
# compression/decompression is wired correctly.
@@ -110,44 +109,13 @@ def test_encode_decode_roundtrip_with_transpose(self) -> None:
110109
np.testing.assert_array_equal(arr, decoded.as_numpy_array())
111110

112111
def test_rejects_non_sync_codec(self) -> None:
113-
# Construction must raise TypeError when a codec lacks SupportsSyncCodec.
114-
115-
class AsyncOnlyCodec(ArrayBytesCodec):
116-
is_fixed_size = True
117-
118-
async def _decode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> NDBuffer:
119-
raise NotImplementedError # pragma: no cover
120-
121-
async def _encode_single(
122-
self, chunk_array: NDBuffer, chunk_spec: ArraySpec
123-
) -> Buffer | None:
124-
raise NotImplementedError # pragma: no cover
125-
126-
def compute_encoded_size(self, input_byte_length: int, _chunk_spec: ArraySpec) -> int:
127-
return input_byte_length # pragma: no cover
128-
112+
"""Construction must raise TypeError when a codec lacks SupportsSyncCodec."""
129113
spec = _make_array_spec((100,), np.dtype("float64"))
130114
with pytest.raises(TypeError, match="AsyncOnlyCodec"):
131115
ChunkTransform(codecs=(AsyncOnlyCodec(),), array_spec=spec)
132116

133117
def test_rejects_mixed_sync_and_non_sync(self) -> None:
134-
# Even if some codecs support sync, a single non-sync codec should
135-
# cause construction to fail.
136-
137-
class AsyncOnlyCodec(ArrayBytesCodec):
138-
is_fixed_size = True
139-
140-
async def _decode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> NDBuffer:
141-
raise NotImplementedError # pragma: no cover
142-
143-
async def _encode_single(
144-
self, chunk_array: NDBuffer, chunk_spec: ArraySpec
145-
) -> Buffer | None:
146-
raise NotImplementedError # pragma: no cover
147-
148-
def compute_encoded_size(self, input_byte_length: int, _chunk_spec: ArraySpec) -> int:
149-
return input_byte_length # pragma: no cover
150-
118+
"""Even if some codecs support sync, a single non-sync codec causes failure."""
151119
spec = _make_array_spec((3, 4), np.dtype("float64"))
152120
with pytest.raises(TypeError, match="AsyncOnlyCodec"):
153121
ChunkTransform(
@@ -179,7 +147,7 @@ def test_encode_returns_none_propagation(self) -> None:
179147
# don't store it"), encode must short-circuit and return None
180148
# instead of passing None into the next codec.
181149

182-
class NoneReturningAACodec(TransposeCodec):
150+
class NoneReturningAACodec(TransposeCodec): # type: ignore[misc]
183151
"""An ArrayArrayCodec that always returns None from encode."""
184152

185153
def _encode_sync(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer | None:

0 commit comments

Comments
 (0)