@@ -258,21 +258,56 @@ def test_cli_macsima(runner: CliRunner, dataset: str) -> None:
258258 _ = read_zarr (output_zarr )
259259
260260
261- def test_collect_map_annotation_values_merges_all_keys_first_wins () -> None :
261+ def test_collect_map_annotation_values_with_no_duplicate_keys () -> None :
262262 ome = OME (
263263 structured_annotations = StructuredAnnotations (
264264 map_annotations = [
265265 MapAnnotation (value = {"a" : "1" , "b" : "2" }),
266- MapAnnotation (value = {"b" : "99" , "c" : "3" }),
266+ MapAnnotation (value = {"c" : "3" }),
267+ ]
268+ )
269+ )
270+
271+ result = _collect_map_annotation_values (ome )
272+
273+ assert result == {"a" : "1" , "b" : "2" , "c" : "3" }
274+
275+
276+ def test_collect_map_annotations_values_with_duplicate_keys_identical_values () -> None :
277+ ome = OME (
278+ structured_annotations = StructuredAnnotations (
279+ map_annotations = [
280+ MapAnnotation (value = {"a" : "1" , "b" : "2" }),
281+ MapAnnotation (value = {"b" : "2" , "c" : "3" }),
267282 ]
268283 )
269284 )
270285
271286 result = _collect_map_annotation_values (ome )
287+ # Key should only be returned once
288+ assert result == {"a" : "1" , "b" : "2" , "c" : "3" }
289+
290+
291+ def test_collect_map_annotations_values_with_duplicate_keys_different_values () -> None :
292+ ome = OME (
293+ structured_annotations = StructuredAnnotations (
294+ map_annotations = [
295+ MapAnnotation (value = {"a" : "1" , "b" : "2" }),
296+ MapAnnotation (value = {"b" : "99" , "c" : "3" }),
297+ ]
298+ )
299+ )
300+ import re
301+
302+ # The parser should throw a warning when duplicate keys with different values are found
303+ with pytest .warns (
304+ UserWarning ,
305+ match = re .escape ("Found different value for b: 99. The parser will only use the first found value, which is 2!" ),
306+ ):
307+ result = _collect_map_annotation_values (ome )
272308
309+ # The parser should return only the first found value.
273310 assert result == {"a" : "1" , "b" : "2" , "c" : "3" }
274- # ensure later duplicate "b" did not overwrite
275- assert result ["b" ] == "2"
276311
277312
278313def test_collect_map_annotation_values_handles_missing_sa_and_empty_list () -> None :
0 commit comments