fix(LamNI): update tests for prompts/kwargs added earlier this branch
CI for csaxs_bec / test (pull_request) Successful in 1m45s
Read the Docs Deploy Trigger / trigger-rtd-webhook (push) Successful in 2s
CI for csaxs_bec / test (push) Successful in 1m59s

Several tomo_scan()/tomo_alignment_scan()/find_rotation_center() tests
started failing (CI) after recent commits on this branch introduced new
input()-backed confirmation/sample-name prompts, an
alignment_scan_progress GUI proxy, and tomo_queue_execute()'s
interactive=False kwarg -- none of which the existing test fixtures or
assertions were updated for. Mock/bypass the new prompts and GUI calls,
add the missing _alignment_scan_progress_proxy to the bare-object test
fixture, and update two assertions (tomo_queue interactive kwarg,
account-less sample registration) to match the intended new behavior.
This commit was merged in pull request #278.
This commit is contained in:
x01dc
2026-07-28 09:53:59 +02:00
parent 56467682a9
commit 13e9cb21e4
4 changed files with 33 additions and 10 deletions
@@ -13,7 +13,11 @@ import numpy as np
import pytest
import csaxs_bec.bec_ipython_client.plugins.LamNI.lamni as lamni_module
from csaxs_bec.bec_ipython_client.plugins.LamNI.lamni import LamNI, _ProgressProxy
from csaxs_bec.bec_ipython_client.plugins.LamNI.lamni import (
LamNI,
_AlignmentScanProgressProxy,
_ProgressProxy,
)
class FakeClient:
@@ -54,12 +58,16 @@ def make_lamni(monkeypatch, xray_eye_fit=None):
obj = object.__new__(LamNI)
obj.client = FakeClient()
obj._progress_proxy = _ProgressProxy(obj.client)
obj._alignment_scan_progress_proxy = _AlignmentScanProgressProxy(obj.client)
obj.tomo_id = -1
obj.sample_name = "test"
obj.OMNYTools = types.SimpleNamespace(printgreenbold=lambda msg: None)
obj._scilog_calls = []
obj.write_to_scilog = lambda content, tags: obj._scilog_calls.append((content, tags))
obj.leye_out = lambda: None
obj.lamnigui_show_alignment_progress = lambda: None
obj._lamnigui_update_alignment_progress = lambda: None
obj._confirm_sequence_override = lambda *a, **k: True
if xray_eye_fit is not None:
obj.client.set_global_var("tomo_fit_xray_eye", xray_eye_fit)
@@ -75,6 +83,7 @@ def make_lamni(monkeypatch, xray_eye_fit=None):
def test_tomo_alignment_scan_aborts_without_xray_eye_fit(monkeypatch):
lamni = make_lamni(monkeypatch, xray_eye_fit=None)
lamni._confirm_sequence_override = lambda *a, **k: False
calls = []
lamni.tomo_scan_projection = lambda angle: calls.append(angle)
@@ -169,6 +169,10 @@ def make_lamni_for_tomo_scan(
obj.lamnigui_show_progress = lambda: None
obj.at_each_angle_hook = None
obj.OMNYTools = types.SimpleNamespace(printgreenbold=lambda msg: None)
# These tests exercise tomo_scan()'s account-handling/heartbeat/progress-GUI
# logic, not the fine-alignment confirmation gate -- bypass it so it never
# blocks on input().
obj._confirm_sequence_override = lambda *a, **k: True
monkeypatch.setitem(
builtins.__dict__,
"bec",
@@ -184,18 +188,24 @@ def make_lamni_for_tomo_scan(
return obj
def test_tomo_scan_skips_sample_database_when_no_active_account(monkeypatch):
"""Empty active_account (e.g. a dev/sim session) must not crash and must
not try to register a sample -- tomo_id falls back to 0, mirroring
Flomni.tomo_scan()'s identical guard."""
def test_tomo_scan_registers_sample_even_without_active_account(monkeypatch):
"""Empty active_account (e.g. a dev/sim session) must not crash -- it is
still passed through to add_sample_database() (as ""), letting
TomoIDManager.register() decide the outcome (test-server registration)
instead of pre-empting it with a hardcoded tomo_id=0."""
lamni = make_lamni_for_tomo_scan(monkeypatch, 45.0, active_account="")
lamni.add_sample_database = lambda *a, **k: (_ for _ in ()).throw(
AssertionError("add_sample_database must not be called with no active account")
)
recorded = {}
def _fake_add_sample_database(samplename, date, eaccount, scan_number, setup, info, user):
recorded["eaccount"] = eaccount
return 7
lamni.add_sample_database = _fake_add_sample_database
lamni.tomo_scan()
assert lamni.tomo_id == 0
assert recorded["eaccount"] == ""
assert lamni.tomo_id == 7
def test_tomo_scan_registers_sample_with_plain_string_account(monkeypatch):
@@ -122,7 +122,7 @@ def test_tomo_queue_execute_runs_fresh_job_then_marks_done():
lamni.tomo_queue_add(label="job1")
lamni.tomo_queue_execute()
assert calls == [("scan", (), {})]
assert calls == [("scan", (), {"interactive": False})]
job = lamni._tomo_queue_proxy.as_list()[0]
assert job["status"] == "done"
@@ -158,6 +158,10 @@ def _make_calibration_align(client):
align.lamni.loptics_out = mock.MagicMock()
align.lamni.losa_out = mock.MagicMock()
align.lamni.lamnigui_show_xeyealign = mock.MagicMock()
# _sync_sample_name(prompt=True) calls lamni._get_val(), which reads from
# input() -- keep the current default (as if Enter was pressed) instead of
# blocking on stdin.
align.lamni._get_val = lambda msg, default_value, data_type: default_value
# Replace the real Scans proxy (which would try to talk to a live scan
# server) with a plain mock -- these tests only care that
# lamni_move_to_scan_center is *called* with the right kwargs.