|
8 | 8 | import pytest |
9 | 9 | from numcodecs import GZip |
10 | 10 |
|
| 11 | +try: |
| 12 | + from numcodecs.errors import UnknownCodecError |
| 13 | +except ImportError: |
| 14 | + # Older versions of numcodecs don't have a separate errors module |
| 15 | + UnknownCodecError = ValueError |
| 16 | + |
11 | 17 | from zarr import config, create_array, open_array |
12 | 18 | from zarr.abc.numcodec import _is_numcodec, _is_numcodec_cls |
13 | 19 | from zarr.codecs import numcodecs as _numcodecs |
@@ -243,6 +249,13 @@ def test_generic_filter_packbits() -> None: |
243 | 249 | ], |
244 | 250 | ) |
245 | 251 | def test_generic_checksum(codec_class: type[_numcodecs._NumcodecsBytesBytesCodec]) -> None: |
| 252 | + # Check if the codec is available in numcodecs |
| 253 | + try: |
| 254 | + with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): |
| 255 | + codec_class()._codec # noqa: B018 |
| 256 | + except UnknownCodecError as e: # pragma: no cover |
| 257 | + pytest.skip(f"{codec_class.codec_name} is not available in numcodecs: {e}") |
| 258 | + |
246 | 259 | data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16)) |
247 | 260 |
|
248 | 261 | with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): |
@@ -352,8 +365,12 @@ def test_to_dict() -> None: |
352 | 365 | ], |
353 | 366 | ) |
354 | 367 | def test_codecs_pickleable(codec_cls: type[_numcodecs._NumcodecsCodec]) -> None: |
355 | | - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): |
356 | | - codec = codec_cls() |
| 368 | + # Check if the codec is available in numcodecs |
| 369 | + try: |
| 370 | + with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): |
| 371 | + codec = codec_cls() |
| 372 | + except UnknownCodecError as e: # pragma: no cover |
| 373 | + pytest.skip(f"{codec_cls.codec_name} is not available in numcodecs: {e}") |
357 | 374 |
|
358 | 375 | expected = codec |
359 | 376 |
|
|
0 commit comments