Update unit tests for new cancel behaviour

This commit is contained in:
Julian Stirling 2026-07-02 16:27:51 +01:00
parent 26a2e1a582
commit d25ebabc77
2 changed files with 16 additions and 8 deletions

View file

@ -351,10 +351,16 @@ class SmartScanThing(OFMThing):
finally:
# Save some final details but not set to the base model until after
# resetting valued and unlocking just in case somehow pydantic errors.
if self._scan_data is not None:
final_image_count = self._scan_data.image_count
if self._preview_stitcher is not None:
last_timestamp = self.latest_preview_stitch_time
final_image_count = (
self._scan_data.image_count if self._scan_data is not None else None
)
last_timestamp = (
self.latest_preview_stitch_time
if self._preview_stitcher is not None
else None
)
# However the scan finishes, unset all variables and release lock
self._ongoing_scan = None
self._scan_data = None
@ -364,7 +370,9 @@ class SmartScanThing(OFMThing):
# Set the final details so they persist until the next scan
if self._latest_scan_live_details is not None:
if final_image_count is not None:
self._latest_scan_live_details.image_count = final_image_count
if last_timestamp is not None:
self._latest_scan_live_details.stitch_timestamp = last_timestamp
self._latest_scan_live_details.scan_phase = "Complete"

View file

@ -559,7 +559,7 @@ def test_run_scan_cancelled(scan_thing_mocked_for_run_scan, caplog, mocker):
scan_thing, "_main_scan_loop", side_effect=InvocationCancelledError()
)
result, logs, calls = check_run_scan(scan_thing, caplog)
result, logs, calls = check_run_scan(scan_thing, caplog, InvocationCancelledError)
assert result == "cancelled by user"
# No logs at warning level.
@ -571,7 +571,7 @@ def test_run_scan_cancelled(scan_thing_mocked_for_run_scan, caplog, mocker):
"cam_change_streaming_mode_calls": 2,
"main_scan_loop_calls": 1,
"return_to_start_calls": 1,
"perform_final_stitch_calls": 1,
"perform_final_stitch_calls": 0,
"save_scan_data_calls": 2,
}
assert calls == expected_calls_numbers