1212from zarr .abc .numcodec import Numcodec , _is_numcodec_cls
1313from zarr .codecs import numcodecs as _numcodecs
1414from zarr .codecs ._v2 import codec_json_v2_to_v3
15- from zarr .core .common import CodecJSON_V2 , ZarrFormat
1615from zarr .errors import ZarrUserWarning
1716from zarr .registry import get_numcodec
1817
1918if TYPE_CHECKING :
2019 from collections .abc import Iterator
2120
21+ from zarr .core .common import CodecJSON_V2 , ZarrFormat
22+
2223CODECS_WITH_SPECS : Final = ("zstd" , "gzip" , "blosc" )
2324
2425
@@ -57,7 +58,7 @@ def codec_conf() -> Iterator[Any]:
5758
5859
5960def test_get_numcodec () -> None :
60- assert get_numcodec ({"id" : "gzip" , "level" : 2 }) == GZip (level = 2 ) # type: ignore[typeddict-unknown-key]
61+ assert get_numcodec ({"id" : "gzip" , "level" : 2 }) == GZip (level = 2 )
6162
6263
6364def test_is_numcodec () -> None :
@@ -227,7 +228,7 @@ def test_generic_filter_packbits() -> None:
227228 b = open_array (a .store , mode = "r" )
228229 np .testing .assert_array_equal (data , b [:, :])
229230
230- with pytest .raises (ValueError , match = ".*requires bool dtype.*" ):
231+ with pytest .raises (ValueError , match = r ".*requires bool dtype.*" ):
231232 create_array (
232233 {},
233234 shape = data .shape ,
@@ -456,7 +457,7 @@ def test_bytes_to_bytes_codec_json_v2_v3(
456457 """Test JSON serialization for bytes-to-bytes codecs in both V2 and V3 formats."""
457458 codec = codec_class (** codec_config )
458459
459- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
460+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
460461 # Test V2 serialization
461462 v2_json = codec .to_json (zarr_format = 2 )
462463 assert v2_json == expected_v2
@@ -553,7 +554,7 @@ def test_array_to_array_codec_json_v2_v3(
553554 codec = codec_class (** codec_config )
554555
555556 # Many codecs emit warnings about unstable specifications
556- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
557+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
557558 # Test V2 serialization
558559 v2_json = codec .to_json (zarr_format = 2 )
559560 assert v2_json == expected_v2
@@ -655,10 +656,10 @@ def test_checksum_codec_json_v2_v3(
655656 codec = codec_class (** codec_config )
656657
657658 # Helper function to compare dictionaries with potential numpy arrays
658- def compare_json_dicts (actual , expected ) :
659+ def compare_json_dicts (actual : Any , expected : Any ) -> bool :
659660 if set (actual .keys ()) != set (expected .keys ()):
660661 return False
661- for key in actual . keys () :
662+ for key in actual :
662663 actual_val = actual [key ]
663664 expected_val = expected [key ]
664665 if isinstance (actual_val , np .ndarray ) and isinstance (expected_val , np .ndarray ):
@@ -675,7 +676,7 @@ def compare_json_dicts(actual, expected):
675676 return True
676677
677678 # Many codecs emit warnings about unstable specifications
678- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
679+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
679680 # Test V2 serialization
680681 v2_json = codec .to_json (zarr_format = 2 )
681682 assert compare_json_dicts (v2_json , expected_v2 ), (
@@ -812,18 +813,18 @@ def test_array_to_bytes_codec_json_v2_v3(
812813 """Test JSON serialization for array-to-bytes codecs in both V2 and V3 formats."""
813814 try :
814815 codec = codec_class (** codec_config )
815- codec ._codec # Try to access the underlying codec to check if it's available
816+ _ = codec ._codec # Try to access the underlying codec to check if it's available
816817 except (ValueError , ImportError ) as e :
817818 if "codec not available" in str (e ) or "not available" in str (e ):
818819 pytest .skip (f"{ codec_class .codec_name } is not available: { e } " )
819820 else :
820821 raise
821822
822823 # Helper function to compare dictionaries with potential numpy arrays
823- def compare_json_dicts (actual , expected ) :
824+ def compare_json_dicts (actual : Any , expected : Any ) -> bool :
824825 if set (actual .keys ()) != set (expected .keys ()):
825826 return False
826- for key in actual . keys () :
827+ for key in actual :
827828 actual_val = actual [key ]
828829 expected_val = expected [key ]
829830 if isinstance (actual_val , np .ndarray ) and isinstance (expected_val , np .ndarray ):
@@ -840,7 +841,7 @@ def compare_json_dicts(actual, expected):
840841 return True
841842
842843 # Many codecs emit warnings about unstable specifications
843- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
844+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
844845 # Test V2 serialization
845846 v2_json = codec .to_json (zarr_format = 2 )
846847 assert compare_json_dicts (v2_json , expected_v2 ), (
@@ -872,9 +873,6 @@ def compare_json_dicts(actual, expected):
872873
873874def test_json_v3_string_format () -> None :
874875 """Test that V3 codecs can be serialized and deserialized from string format."""
875- # Test with a simple codec
876- codec = _numcodecs .LZ4 ()
877-
878876 # Test string-only V3 format (codec name without configuration)
879877 v3_string = "lz4"
880878 codec_from_string = _numcodecs .LZ4 .from_json (v3_string )
@@ -895,7 +893,7 @@ def test_json_mixed_format_compatibility() -> None:
895893 original_codec = _numcodecs .Zlib (level = 9 )
896894
897895 # Create both formats
898- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
896+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
899897 v2_json = original_codec .to_json (zarr_format = 2 )
900898 v3_json = original_codec .to_json (zarr_format = 3 )
901899
@@ -917,14 +915,14 @@ def test_json_error_handling() -> None:
917915 """Test error handling for invalid JSON inputs."""
918916 # Test None input
919917 with pytest .raises (AttributeError ):
920- _numcodecs .LZ4 .from_json (None ) # type: ignore[arg-type]
918+ _numcodecs .LZ4 .from_json (None )
921919
922920 # Test list input (doesn't have get method)
923921 with pytest .raises (AttributeError ):
924- _numcodecs .LZ4 .from_json ([]) # type: ignore[arg-type]
922+ _numcodecs .LZ4 .from_json ([])
925923
926924
927- @pytest .mark .filterwarnings ("ignore" , category = ZarrUserWarning )
925+ @pytest .mark .filterwarnings ("ignore::zarr.errors. ZarrUserWarning" )
928926@pytest .mark .parametrize (
929927 ("codec" , "expected" ),
930928 [
@@ -1070,10 +1068,11 @@ def test_json_roundtrip_default_config(
10701068 )
10711069
10721070
1073- def compare_json_dicts (actual , expected ):
1071+ def compare_json_dicts (actual : Any , expected : Any ) -> bool :
1072+ """Compare two dictionaries that may contain numpy arrays."""
10741073 if set (actual .keys ()) != set (expected .keys ()):
10751074 return False
1076- for key in actual . keys () :
1075+ for key in actual :
10771076 actual_val = actual [key ]
10781077 expected_val = expected [key ]
10791078 if isinstance (actual_val , np .ndarray ) and isinstance (expected_val , np .ndarray ):
0 commit comments