|
17 | 17 | from zarr.core.dtype import get_data_type_from_native_dtype |
18 | 18 |
|
19 | 19 |
|
| 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 | + |
20 | 35 | def _make_array_spec(shape: tuple[int, ...], dtype: np.dtype[np.generic]) -> ArraySpec: |
21 | 36 | zdtype = get_data_type_from_native_dtype(dtype) |
22 | 37 | return ArraySpec( |
@@ -63,22 +78,6 @@ def test_encode_decode_roundtrip_bytes_only(self) -> None: |
63 | 78 | decoded = chain.decode(encoded) |
64 | 79 | np.testing.assert_array_equal(arr, decoded.as_numpy_array()) |
65 | 80 |
|
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 | | - |
82 | 81 | def test_encode_decode_roundtrip_with_compression(self) -> None: |
83 | 82 | # Round-trip with a BB codec (GzipCodec) to verify that bytes-bytes |
84 | 83 | # compression/decompression is wired correctly. |
@@ -110,44 +109,13 @@ def test_encode_decode_roundtrip_with_transpose(self) -> None: |
110 | 109 | np.testing.assert_array_equal(arr, decoded.as_numpy_array()) |
111 | 110 |
|
112 | 111 | 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.""" |
129 | 113 | spec = _make_array_spec((100,), np.dtype("float64")) |
130 | 114 | with pytest.raises(TypeError, match="AsyncOnlyCodec"): |
131 | 115 | ChunkTransform(codecs=(AsyncOnlyCodec(),), array_spec=spec) |
132 | 116 |
|
133 | 117 | 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.""" |
151 | 119 | spec = _make_array_spec((3, 4), np.dtype("float64")) |
152 | 120 | with pytest.raises(TypeError, match="AsyncOnlyCodec"): |
153 | 121 | ChunkTransform( |
@@ -179,7 +147,7 @@ def test_encode_returns_none_propagation(self) -> None: |
179 | 147 | # don't store it"), encode must short-circuit and return None |
180 | 148 | # instead of passing None into the next codec. |
181 | 149 |
|
182 | | - class NoneReturningAACodec(TransposeCodec): |
| 150 | + class NoneReturningAACodec(TransposeCodec): # type: ignore[misc] |
183 | 151 | """An ArrayArrayCodec that always returns None from encode.""" |
184 | 152 |
|
185 | 153 | def _encode_sync(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer | None: |
|
0 commit comments