Skip to content

Commit 33a2023

Browse files
d-v-bclaude
andcommitted
test(codecs): parametrize blosc cname/shuffle coverage and JSON roundtrip
Backfill missing coverage: previously every test in the blosc suite used only "lz4" or "zstd" for cname and only "bitshuffle" or "shuffle" for shuffle. Add four parametrized tests driven by BLOSC_CNAME / BLOSC_SHUFFLE: - accepts_all_cnames / accepts_all_shuffles: every value in the runtime tuple is accepted by BloscCodec and round-trips on the stored attribute. Catches drift between the BloscCnameLiteral / BloscShuffleLiteral type aliases and their runtime BLOSC_* counterparts. - json_roundtrip_all_cnames / json_roundtrip_all_shuffles: BloscCodec to_dict / from_dict preserves every value. Codec fields are fully specified so the test doesn't trip over tunable-attribute state, which is not part of the JSON form. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9eebe01 commit 33a2023

1 file changed

Lines changed: 62 additions & 1 deletion

File tree

tests/test_codecs/test_blosc.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
import zarr
1212
from zarr.abc.codec import SupportsSyncCodec
1313
from zarr.codecs import BloscCodec
14-
from zarr.codecs.blosc import BloscCname, BloscShuffle, BloscShuffleLiteral
14+
from zarr.codecs.blosc import (
15+
BLOSC_CNAME,
16+
BLOSC_SHUFFLE,
17+
BloscCname,
18+
BloscCnameLiteral,
19+
BloscShuffle,
20+
BloscShuffleLiteral,
21+
)
1522
from zarr.core.array_spec import ArrayConfig, ArraySpec
1623
from zarr.core.buffer import default_buffer_prototype
1724
from zarr.core.dtype import UInt16, get_data_type_from_native_dtype
@@ -150,6 +157,60 @@ def test_blosc_codec_sync_roundtrip() -> None:
150157
np.testing.assert_array_equal(arr, result)
151158

152159

160+
@pytest.mark.parametrize("cname", BLOSC_CNAME)
161+
def test_blosc_codec_accepts_all_cnames(cname: BloscCnameLiteral) -> None:
162+
"""
163+
Every compressor name in BLOSC_CNAME is accepted by BloscCodec and round-trips
164+
to the same value on the stored attribute. Adding a new value to the
165+
BloscCnameLiteral type alias without also adding it to BLOSC_CNAME (or vice
166+
versa) is caught here.
167+
"""
168+
codec = BloscCodec(cname=cname)
169+
assert codec.cname == cname
170+
171+
172+
@pytest.mark.parametrize("shuffle", BLOSC_SHUFFLE)
173+
def test_blosc_codec_accepts_all_shuffles(shuffle: BloscShuffleLiteral) -> None:
174+
"""
175+
Every shuffle mode in BLOSC_SHUFFLE is accepted by BloscCodec and round-trips
176+
to the same value on the stored attribute. Adding a new value to the
177+
BloscShuffleLiteral type alias without also adding it to BLOSC_SHUFFLE (or
178+
vice versa) is caught here.
179+
"""
180+
codec = BloscCodec(shuffle=shuffle)
181+
assert codec.shuffle == shuffle
182+
183+
184+
@pytest.mark.parametrize("cname", BLOSC_CNAME)
185+
def test_blosc_codec_json_roundtrip_all_cnames(cname: BloscCnameLiteral) -> None:
186+
"""
187+
JSON serialization (to_dict / from_dict) preserves every cname. Guards
188+
against drift in the codec's V3 JSON form for any compressor option.
189+
190+
The non-cname fields are fully specified so the codec has no tunable
191+
attributes; tunability is not part of the JSON form and would otherwise
192+
cause spurious round-trip mismatches.
193+
"""
194+
codec = BloscCodec(typesize=1, cname=cname, clevel=5, shuffle="shuffle", blocksize=0)
195+
restored = BloscCodec.from_dict(codec.to_dict())
196+
assert restored == codec
197+
198+
199+
@pytest.mark.parametrize("shuffle", BLOSC_SHUFFLE)
200+
def test_blosc_codec_json_roundtrip_all_shuffles(shuffle: BloscShuffleLiteral) -> None:
201+
"""
202+
JSON serialization (to_dict / from_dict) preserves every shuffle mode.
203+
Guards against drift in the codec's V3 JSON form for any shuffle option.
204+
205+
The non-shuffle fields are fully specified so the codec has no tunable
206+
attributes; tunability is not part of the JSON form and would otherwise
207+
cause spurious round-trip mismatches.
208+
"""
209+
codec = BloscCodec(typesize=1, cname="zstd", clevel=5, shuffle=shuffle, blocksize=0)
210+
restored = BloscCodec.from_dict(codec.to_dict())
211+
assert restored == codec
212+
213+
153214
@pytest.mark.parametrize(
154215
("enum_cls", "member", "expected"),
155216
[

0 commit comments

Comments
 (0)