@@ -173,3 +173,96 @@ def test_parse_filtercolor_metadata_with_filter_pair() -> None:
173173 assert result is not None
174174 assert "Channel1" in result
175175 assert result ["Channel1" ] == (1.0 , 128 / 255 , 0.0 )
176+
177+
178+ def test_parse_scancolortable_rgb_and_named_colors () -> None :
179+ """Test parsing of ScanColorTable with RGB and named color values."""
180+ xml_str = """
181+ <root>
182+ <ScanColorTable>
183+ <ScanColorTable-k>FITC_Exc_Em</ScanColorTable-k>
184+ <ScanColorTable-v>0,255,0</ScanColorTable-v>
185+ <ScanColorTable-k>DAPI_Exc_Em</ScanColorTable-k>
186+ <ScanColorTable-v>Blue</ScanColorTable-v>
187+ <ScanColorTable-k>Cy3_Exc_Em</ScanColorTable-k>
188+ <ScanColorTable-v></ScanColorTable-v>
189+ </ScanColorTable>
190+ </root>
191+ """
192+ root = ElementTree .fromstring (xml_str )
193+ result = wsireader .TIFFWSIReader ._parse_scancolortable (root )
194+
195+ assert result is not None
196+ assert result ["FITC" ] == (0.0 , 1.0 , 0.0 )
197+ assert result ["DAPI" ] == (0.0 , 0.0 , 1.0 )
198+ assert result ["Cy3" ] is None # Empty value is incluided but not converted
199+
200+
201+ def test_get_namespace_extraction () -> None :
202+ """Test extraction of XML namespace from root tag."""
203+ # Case with namespace
204+ xml_with_ns = '<ome:OME xmlns:ome="http://www.openmicroscopy.org/Schemas/OME/2016-06"></ome:OME>'
205+ root_with_ns = ElementTree .fromstring (xml_with_ns )
206+ result_with_ns = wsireader .TIFFWSIReader ._get_namespace (root_with_ns )
207+ assert result_with_ns == {"ns" : "http://www.openmicroscopy.org/Schemas/OME/2016-06" }
208+
209+ # Case without namespace
210+ xml_without_ns = "<OME></OME>"
211+ root_without_ns = ElementTree .fromstring (xml_without_ns )
212+ result_without_ns = wsireader .TIFFWSIReader ._get_namespace (root_without_ns )
213+ assert result_without_ns == {}
214+
215+
216+ def test_extract_dye_mapping () -> None :
217+ """Test extraction of dye mapping including missing and valid cases."""
218+ # Case with valid ChannelPriv entries
219+ xml_valid = """
220+ <OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06">
221+ <StructuredAnnotations>
222+ <XMLAnnotation>
223+ <Value>
224+ <ChannelPriv ID="Channel:0" FluorescenceChannel="FITC"/>
225+ <ChannelPriv ID="Channel:1" FluorescenceChannel="DAPI"/>
226+ </Value>
227+ </XMLAnnotation>
228+ </StructuredAnnotations>
229+ </OME>
230+ """
231+ root_valid = ElementTree .fromstring (xml_valid )
232+ ns = {"ns" : "http://www.openmicroscopy.org/Schemas/OME/2016-06" }
233+ result_valid = wsireader .TIFFWSIReader ._extract_dye_mapping (root_valid , ns )
234+ assert result_valid == {"Channel:0" : "FITC" , "Channel:1" : "DAPI" }
235+
236+ # Case with missing <Value>
237+ xml_missing_value = """
238+ <OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06">
239+ <StructuredAnnotations>
240+ <XMLAnnotation>
241+ </XMLAnnotation>
242+ </StructuredAnnotations>
243+ </OME>
244+ """
245+ root_missing_value = ElementTree .fromstring (xml_missing_value )
246+ result_missing_value = wsireader .TIFFWSIReader ._extract_dye_mapping (
247+ root_missing_value , ns
248+ )
249+ assert result_missing_value == {}
250+
251+ # Case with ChannelPriv missing attributes
252+ xml_missing_attrs = """
253+ <OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06">
254+ <StructuredAnnotations>
255+ <XMLAnnotation>
256+ <Value>
257+ <ChannelPriv FluorescenceChannel="FITC"/>
258+ <ChannelPriv ID="Channel:2"/>
259+ </Value>
260+ </XMLAnnotation>
261+ </StructuredAnnotations>
262+ </OME>
263+ """
264+ root_missing_attrs = ElementTree .fromstring (xml_missing_attrs )
265+ result_missing_attrs = wsireader .TIFFWSIReader ._extract_dye_mapping (
266+ root_missing_attrs , ns
267+ )
268+ assert result_missing_attrs == {}
0 commit comments