Skip to content

Commit b68c4f3

Browse files
committed
test: cover unparseable time format fallback in DM spectrum image parser
Add test for the for-else branch in parse_dm3_spectrum_image_info where both time format strings fail to parse Start/End time values, ensuring no Acquisition Duration is set.
1 parent 4df59a2 commit b68c4f3

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/unit/test_extractors/test_digital_micrograph.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,35 @@ def __setitem__(self, key, value):
682682
assert "Profile extension field injection" in caplog.text
683683
assert "failed" in caplog.text
684684

685+
def test_spectrum_image_unparseable_time_skips_duration(self):
686+
"""Test that unparseable acquisition times do not produce a duration.
687+
688+
When "Start time" and "End time" values are present but cannot be
689+
parsed by any of the known time formats, the function should skip
690+
setting Acquisition Duration rather than raising an error.
691+
"""
692+
mdict = {
693+
"ImageList": {
694+
"TagGroup0": {
695+
"ImageTags": {
696+
"SI": {
697+
"Acquisition": {
698+
"Start time": "not-a-time",
699+
"End time": "also-not-a-time",
700+
},
701+
},
702+
},
703+
},
704+
},
705+
"nx_meta": {"DatasetType": "Spectrum"},
706+
}
707+
708+
result = digital_micrograph.parse_dm3_spectrum_image_info(mdict)
709+
710+
# Should not have added Acquisition Duration
711+
si_meta = result["nx_meta"].get("Spectrum Imaging", {})
712+
assert "Acquisition Duration" not in si_meta
713+
685714
def test_quantity_conversion_failure_keeps_original_value(self):
686715
"""Test that failed unit conversions keep original value w/ original field name.
687716

0 commit comments

Comments
 (0)