blissoda.tests.test_stop_scan_preset#

Unit tests for the StopIntegrateSum attenuation “freeze-mode” state machine.

These tests drive ScanPointIterator._freeze_setup_step directly with a mocked parent preset, no Bliss session is needed. Integration tests are not adequate to check freeze mode as the demo Bliss detector (difflab6) does not respond to changes in attenuation (e.g. via setup_globals.atten.bits).

Functions

test_event_dispatch_drops_malformed_metric(caplog)

Malformed metric events are logged and dropped without crashing.

test_event_dispatch_metric_stop_unknown(caplog)

_check_workflow_events routes each event type to the right sink.

test_find_optimal_atten_for_threshold_selection_rule(mocker)

The helper picks the smallest atten whose predicted intensity is strictly below the threshold; falls back to the strongest available attenuation when no position satisfies; returns None on missing or invalid transmission data.

test_freeze_classification_timeout(caplog, ...)

No frame-0 metric within metric_timeout → default to 'standard'.

test_freeze_spotty_stable()

Spotty-stable branch jumps from safe_atten to predicted-optimal in one move, verifies, applies the +extra_atten bump, then freezes.

test_freeze_spotty_unstable()

Spotty-unstable branch keeps safe_atten and freezes immediately.

test_freeze_standard_convergence_jump_then_verify()

Standard-branch safe-frame loop jumps to the predicted-optimal attenuator position and converges after a single verify iteration.

test_freeze_standard_jump_caps_at_max_atten(caplog)

Count rate too high for any position to predict below threshold: the helper returns max_atten and the loop converges there with a warning.

test_freeze_standard_jump_down_then_verify()

Starting over-attenuated (bits=4, frame max well below threshold) the helper jumps directly down to bits=2; iter 2 verifies and freezes.

test_freeze_standard_jump_falls_back_to_pm1()

When _find_least_atten_below_threshold returns None (e.g. missing transmission data) the safe-frame loop falls back to the legacy ±1 step path driven by _predict_frame_max_at.

test_freeze_standard_jump_then_verify_re_jumps()

Model under-predicted: first jump lands at bits=5 but the actual frame max there is still ≥ threshold; helper picks bits=7; verify at bits=7 → converged.

test_invalid_attenuation_mode_raises(mocker)

test_reactive_mode_does_not_run_frame0_setup()

In reactive mode, _freeze_setup_step is never entered.