@@ -19,11 +19,12 @@ def _make_v01_multiscales(version: str = '0.1') -> list:
1919 return [{'version' : version , 'datasets' : [{'path' : '0' }, {'path' : '1' }]}]
2020
2121
22- def _make_v03_multiscales () -> list :
23- """Minimal OME-Zarr >= v0.3 multiscales — has coordinateTransformations."""
22+ def _make_v03_string_axes_multiscales () -> list :
23+ """OME-Zarr v0.3 multiscales — axes are strings, has coordinateTransformations."""
2424 return [
2525 {
2626 'version' : '0.3' ,
27+ 'axes' : ['z' , 'y' , 'x' ],
2728 'datasets' : [
2829 {
2930 'path' : '0' ,
@@ -36,19 +37,43 @@ def _make_v03_multiscales() -> list:
3637 ]
3738
3839
39- class TestWarnIfOldZarrFormat :
40- """Unit tests for warn_if_old_zarr_format."""
40+ def _make_v04_multiscales () -> list :
41+ """Minimal OME-Zarr >=v0.4 multiscales — dict-axes and coordinateTransformations."""
42+ return [
43+ {
44+ 'version' : '0.4' ,
45+ 'axes' : [
46+ {'name' : 'z' , 'type' : 'space' },
47+ {'name' : 'y' , 'type' : 'space' },
48+ {'name' : 'x' , 'type' : 'space' },
49+ ],
50+ 'datasets' : [
51+ {
52+ 'path' : '0' ,
53+ 'coordinateTransformations' : [
54+ {'type' : 'scale' , 'scale' : [1.0 , 0.5 , 0.5 ]}
55+ ],
56+ }
57+ ],
58+ }
59+ ]
60+
61+
62+ class TestWarnIfNoCoordinateTransforms :
63+ """Unit tests for _warn_if_no_coordinate_transforms."""
4164
4265 def test_v01_emits_warning (self , caplog ):
4366 """v0.1 metadata (no coordinateTransformations) triggers a warning."""
44- from ndevio .bioio_plugins ._compatibility import warn_if_old_zarr_format
67+ from ndevio .bioio_plugins ._compatibility import (
68+ _warn_if_no_coordinate_transforms ,
69+ )
4570
4671 reader = _make_zarr_reader (_make_v01_multiscales ('0.1' ))
4772
4873 with caplog .at_level (
4974 logging .WARNING , logger = 'ndevio.bioio_plugins._compatibility'
5075 ):
51- warn_if_old_zarr_format (reader )
76+ _warn_if_no_coordinate_transforms (reader )
5277
5378 assert len (caplog .records ) == 1
5479 assert '0.1' in caplog .records [0 ].message
@@ -57,47 +82,70 @@ def test_v01_emits_warning(self, caplog):
5782
5883 def test_v02_emits_warning (self , caplog ):
5984 """v0.2 metadata also triggers a warning."""
60- from ndevio .bioio_plugins ._compatibility import warn_if_old_zarr_format
85+ from ndevio .bioio_plugins ._compatibility import (
86+ _warn_if_no_coordinate_transforms ,
87+ )
6188
6289 reader = _make_zarr_reader (_make_v01_multiscales ('0.2' ))
6390
6491 with caplog .at_level (
6592 logging .WARNING , logger = 'ndevio.bioio_plugins._compatibility'
6693 ):
67- warn_if_old_zarr_format (reader )
94+ _warn_if_no_coordinate_transforms (reader )
6895
6996 assert len (caplog .records ) == 1
7097 assert '0.2' in caplog .records [0 ].message
7198
72- def test_v03_no_warning (self , caplog ):
73- """v0.3+ metadata (has coordinateTransformations) emits no warning."""
74- from ndevio .bioio_plugins ._compatibility import warn_if_old_zarr_format
99+ def test_v03_with_transforms_no_warning (self , caplog ):
100+ """v0.3 metadata (has coordinateTransformations) emits no warning."""
101+ from ndevio .bioio_plugins ._compatibility import (
102+ _warn_if_no_coordinate_transforms ,
103+ )
75104
76- reader = _make_zarr_reader (_make_v03_multiscales ())
105+ reader = _make_zarr_reader (_make_v03_string_axes_multiscales ())
77106
78107 with caplog .at_level (
79108 logging .WARNING , logger = 'ndevio.bioio_plugins._compatibility'
80109 ):
81- warn_if_old_zarr_format (reader )
110+ _warn_if_no_coordinate_transforms (reader )
111+
112+ assert len (caplog .records ) == 0
113+
114+ def test_v04_no_warning (self , caplog ):
115+ """v0.4 metadata emits no warning."""
116+ from ndevio .bioio_plugins ._compatibility import (
117+ _warn_if_no_coordinate_transforms ,
118+ )
119+
120+ reader = _make_zarr_reader (_make_v04_multiscales ())
121+
122+ with caplog .at_level (
123+ logging .WARNING , logger = 'ndevio.bioio_plugins._compatibility'
124+ ):
125+ _warn_if_no_coordinate_transforms (reader )
82126
83127 assert len (caplog .records ) == 0
84128
85129 def test_empty_multiscales_no_warning (self , caplog ):
86130 """Empty multiscales list does not raise and emits no warning."""
87- from ndevio .bioio_plugins ._compatibility import warn_if_old_zarr_format
131+ from ndevio .bioio_plugins ._compatibility import (
132+ _warn_if_no_coordinate_transforms ,
133+ )
88134
89135 reader = _make_zarr_reader ([])
90136
91137 with caplog .at_level (
92138 logging .WARNING , logger = 'ndevio.bioio_plugins._compatibility'
93139 ):
94- warn_if_old_zarr_format (reader )
140+ _warn_if_no_coordinate_transforms (reader )
95141
96142 assert len (caplog .records ) == 0
97143
98144 def test_unknown_version_in_warning (self , caplog ):
99145 """When version key is missing the warning still fires with a fallback string."""
100- from ndevio .bioio_plugins ._compatibility import warn_if_old_zarr_format
146+ from ndevio .bioio_plugins ._compatibility import (
147+ _warn_if_no_coordinate_transforms ,
148+ )
101149
102150 # No 'version' key, no 'coordinateTransformations'
103151 multiscales = [{'datasets' : [{'path' : '0' }]}]
@@ -106,32 +154,74 @@ def test_unknown_version_in_warning(self, caplog):
106154 with caplog .at_level (
107155 logging .WARNING , logger = 'ndevio.bioio_plugins._compatibility'
108156 ):
109- warn_if_old_zarr_format (reader )
157+ _warn_if_no_coordinate_transforms (reader )
110158
111159 assert len (caplog .records ) == 1
112160 assert 'unknown' in caplog .records [0 ].message .lower ()
113161
114162
163+ class TestNormalizeV03StringAxes :
164+ """Unit tests for _normalize_v03_string_axes."""
165+
166+ def test_string_axes_normalized (self ):
167+ """v0.3 string-axes are converted to v0.4 dict-axes."""
168+ from ndevio .bioio_plugins ._compatibility import (
169+ _normalize_v03_string_axes ,
170+ )
171+
172+ reader = _make_zarr_reader (_make_v03_string_axes_multiscales ())
173+ _normalize_v03_string_axes (reader )
174+
175+ axes = reader ._multiscales_metadata [0 ]['axes' ]
176+ assert all (isinstance (ax , dict ) for ax in axes )
177+ assert axes [0 ] == {'name' : 'z' , 'type' : 'space' }
178+ assert axes [1 ] == {'name' : 'y' , 'type' : 'space' }
179+ assert axes [2 ] == {'name' : 'x' , 'type' : 'space' }
180+
181+ def test_dict_axes_untouched (self ):
182+ """v0.4 dict-axes are not modified."""
183+ from ndevio .bioio_plugins ._compatibility import (
184+ _normalize_v03_string_axes ,
185+ )
186+
187+ reader = _make_zarr_reader (_make_v04_multiscales ())
188+ import copy
189+
190+ original = copy .deepcopy (reader ._multiscales_metadata [0 ]['axes' ])
191+ _normalize_v03_string_axes (reader )
192+
193+ assert reader ._multiscales_metadata [0 ]['axes' ] == original
194+
195+ def test_empty_multiscales (self ):
196+ """No crash on empty multiscales."""
197+ from ndevio .bioio_plugins ._compatibility import (
198+ _normalize_v03_string_axes ,
199+ )
200+
201+ reader = _make_zarr_reader ([])
202+ _normalize_v03_string_axes (reader ) # should not raise
203+
204+
115205class TestNImageCompatibilityGuard :
116- """Integration tests: nImage.__init__ only calls warn_if_old_zarr_format for zarr readers."""
206+ """Integration tests: nImage.__init__ calls apply_ome_zarr_compat_patches for zarr readers."""
117207
118208 def test_non_zarr_reader_skips_check (self , resources_dir ):
119- """A TIFF-backed nImage never calls warn_if_old_zarr_format ."""
209+ """A TIFF-backed nImage never calls apply_ome_zarr_compat_patches ."""
120210 from ndevio import nImage
121211
122212 with patch (
123- 'ndevio.bioio_plugins._compatibility.warn_if_old_zarr_format '
213+ 'ndevio.bioio_plugins._compatibility.apply_ome_zarr_compat_patches '
124214 ) as mock_check :
125215 nImage (resources_dir / 'cells3d2ch_legacy.tiff' )
126216
127217 mock_check .assert_not_called ()
128218
129219 def test_zarr_reader_calls_check (self , resources_dir ):
130- """A zarr-backed nImage calls warn_if_old_zarr_format exactly once."""
220+ """A zarr-backed nImage calls apply_ome_zarr_compat_patches exactly once."""
131221 from ndevio import nImage
132222
133223 with patch (
134- 'ndevio.bioio_plugins._compatibility.warn_if_old_zarr_format '
224+ 'ndevio.bioio_plugins._compatibility.apply_ome_zarr_compat_patches '
135225 ) as mock_check :
136226 nImage (resources_dir / 'dimension_handling_zyx_V3.zarr' )
137227
0 commit comments