@@ -133,15 +133,17 @@ def test_default_mode_read_only(self, tmp_path):
133133
134134
135135class TestMakeCompressor :
136- def test_v2_returns_numcodecs (self , monkeypatch ):
137- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 2 )
138- c = zarr_utils .make_compressor (zarr_utils .DEFAULT_COMPRESSOR_CONFIG )
136+ def test_v2_returns_numcodecs (self ):
137+ c = zarr_utils .make_compressor (
138+ zarr_utils .DEFAULT_COMPRESSOR_CONFIG , zarr_format = 2
139+ )
139140 assert isinstance (c , numcodecs .Blosc )
140141 assert c .get_config () == zarr_utils .DEFAULT_COMPRESSOR_CONFIG
141142
142- def test_v3_returns_blosc_codec (self , monkeypatch ):
143- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 3 )
144- c = zarr_utils .make_compressor (zarr_utils .DEFAULT_COMPRESSOR_CONFIG )
143+ def test_v3_returns_blosc_codec (self ):
144+ c = zarr_utils .make_compressor (
145+ zarr_utils .DEFAULT_COMPRESSOR_CONFIG , zarr_format = 3
146+ )
145147 assert isinstance (c , BloscCodec )
146148 assert c .cname .value == "zstd"
147149 assert c .clevel == 7
@@ -156,31 +158,36 @@ def test_v3_returns_blosc_codec(self, monkeypatch):
156158 (numcodecs .Blosc .BITSHUFFLE , BloscShuffle .bitshuffle ),
157159 ],
158160 )
159- def test_v3_shuffle_mapping (self , monkeypatch , numcodecs_shuffle , v3_shuffle ):
160- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 3 )
161+ def test_v3_shuffle_mapping (self , numcodecs_shuffle , v3_shuffle ):
161162 c = zarr_utils .make_compressor (
162163 {
163164 "id" : "blosc" ,
164165 "cname" : "zstd" ,
165166 "clevel" : 5 ,
166167 "shuffle" : numcodecs_shuffle ,
167- }
168+ },
169+ zarr_format = 3 ,
168170 )
169171 assert c .shuffle == v3_shuffle
170172 assert c .blocksize == 0
171173
172- def test_v3_default_shuffle_when_omitted (self , monkeypatch ):
173- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 3 )
174- c = zarr_utils .make_compressor ({"id" : "blosc" , "cname" : "lz4" , "clevel" : 1 })
174+ def test_v3_default_shuffle_when_omitted (self ):
175+ c = zarr_utils .make_compressor (
176+ {"id" : "blosc" , "cname" : "lz4" , "clevel" : 1 }, zarr_format = 3
177+ )
175178 assert c .shuffle == BloscShuffle .shuffle
176179
180+ @pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
177181 def test_non_blosc_raises (self , zarr_format ):
178182 with pytest .raises (NotImplementedError , match = "Only blosc" ):
179- zarr_utils .make_compressor ({"id" : "zlib" , "level" : 1 })
183+ zarr_utils .make_compressor (
184+ {"id" : "zlib" , "level" : 1 }, zarr_format = zarr_format
185+ )
180186
187+ @pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
181188 def test_missing_id_raises (self , zarr_format ):
182189 with pytest .raises (NotImplementedError , match = "Only blosc" ):
183- zarr_utils .make_compressor ({"cname" : "zstd" })
190+ zarr_utils .make_compressor ({"cname" : "zstd" }, zarr_format = zarr_format )
184191
185192
186193class TestDefaultCompressorConstants :
@@ -576,8 +583,7 @@ class Stub:
576583
577584
578585class TestMoveChunks :
579- def test_v2_layout (self , tmp_path , monkeypatch ):
580- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 2 )
586+ def test_v2_layout (self , tmp_path ):
581587 src = tmp_path / "src"
582588 src .mkdir ()
583589 (src / ".zarray" ).write_text ("{}" )
@@ -587,15 +593,14 @@ def test_v2_layout(self, tmp_path, monkeypatch):
587593 dest_root = tmp_path / "dest"
588594 (dest_root / "arr" ).mkdir (parents = True )
589595
590- zarr_utils .move_chunks (src , dest_root , partition = 0 , name = "arr" )
596+ zarr_utils .move_chunks (src , dest_root , partition = 0 , name = "arr" , zarr_format = 2 )
591597
592598 assert (dest_root / "arr" / "0" ).read_text () == "chunk0"
593599 assert (dest_root / "arr" / "1" ).read_text () == "chunk1"
594600 # Hidden file is left behind.
595601 assert (src / ".zarray" ).exists ()
596602
597- def test_v3_layout (self , tmp_path , monkeypatch ):
598- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 3 )
603+ def test_v3_layout (self , tmp_path ):
599604 src = tmp_path / "src"
600605 (src / "c" ).mkdir (parents = True )
601606 (src / "c" / "0" ).write_text ("chunk0" )
@@ -605,20 +610,19 @@ def test_v3_layout(self, tmp_path, monkeypatch):
605610 dest_root = tmp_path / "dest"
606611 (dest_root / "arr" ).mkdir (parents = True )
607612
608- zarr_utils .move_chunks (src , dest_root , partition = 0 , name = "arr" )
613+ zarr_utils .move_chunks (src , dest_root , partition = 0 , name = "arr" , zarr_format = 3 )
609614
610615 assert (dest_root / "arr" / "c" / "0" ).read_text () == "chunk0"
611616 assert (dest_root / "arr" / "c" / "1" ).read_text () == "chunk1"
612617 assert (src / "c" / ".hidden" ).exists ()
613618
614- def test_v3_missing_c_directory (self , tmp_path , monkeypatch ):
615- monkeypatch .setattr (zarr_utils , "ZARR_FORMAT" , 3 )
619+ def test_v3_missing_c_directory (self , tmp_path ):
616620 src = tmp_path / "src"
617621 src .mkdir ()
618622
619623 dest_root = tmp_path / "dest"
620624 (dest_root / "arr" ).mkdir (parents = True )
621625
622626 # Should not raise even though src/c/ does not exist.
623- zarr_utils .move_chunks (src , dest_root , partition = 0 , name = "arr" )
627+ zarr_utils .move_chunks (src , dest_root , partition = 0 , name = "arr" , zarr_format = 3 )
624628 assert list ((dest_root / "arr" / "c" ).iterdir ()) == []
0 commit comments