fix(tests): patch input() where yesno() actually calls it
CI for csaxs_bec / test (pull_request) Successful in 1m52s
Read the Docs Deploy Trigger / trigger-rtd-webhook (push) Successful in 2s
CI for csaxs_bec / test (push) Successful in 1m48s

find_rotation_center()'s y/n prompts now go through OMNYTools.yesno()
(omny_general_tools.py) instead of a raw input() in x_ray_eye_align.py,
but these tests were still patching input() on the old module -- so
the real input() got called under pytest's captured stdin and raised
"reading from stdin while output is captured".

Patch input() on omny_general_tools instead, where yesno() actually
calls it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit was merged in pull request #294.
This commit is contained in:
x01dcandClaude Sonnet 5 committed 2026-08-14 10:39:12 +02:00
1 parent f0152fe028
commit abb933e10d
1 file changed
+10 -6
@@ -16,6 +16,10 @@ from csaxs_bec.bec_ipython_client.plugins.LamNI.x_ray_eye_align import XrayEyeAl
# pylint: disable=protected-access
XRAY_EYE_ALIGN = "csaxs_bec.bec_ipython_client.plugins.LamNI.x_ray_eye_align"
# find_rotation_center()'s y/n prompts go through OMNYTools.yesno(), which
# calls the real input() from this module -- not from XRAY_EYE_ALIGN -- so
# that's what needs patching to keep these tests from blocking on stdin.
OMNY_GENERAL_TOOLS = "csaxs_bec.bec_ipython_client.plugins.OMNY_shared.omny_general_tools"
class RTControllerMock:
@@ -234,7 +238,7 @@ def test_extended_calibration_accumulates_shift_across_iterations(bec_client_moc
with mock.patch(f"{XRAY_EYE_ALIGN}.dev", dev_mock):
with mock.patch(f"{XRAY_EYE_ALIGN}.umv"):
with mock.patch(f"{XRAY_EYE_ALIGN}.time.sleep"):
with mock.patch(f"{XRAY_EYE_ALIGN}.input", side_effect=["n", "y"]):
with mock.patch(f"{OMNY_GENERAL_TOOLS}.input", side_effect=["n", "y"]):
align.find_rotation_center(sample_type="extended", apply=False)
calls = align.scans.lamni_move_to_scan_center.call_args_list
@@ -309,7 +313,7 @@ def test_find_rotation_center_isolated_computes_midpoint(bec_client_mock):
with mock.patch(f"{XRAY_EYE_ALIGN}.dev", dev_mock):
with mock.patch(f"{XRAY_EYE_ALIGN}.umv"):
with mock.patch(f"{XRAY_EYE_ALIGN}.time.sleep"):
with mock.patch(f"{XRAY_EYE_ALIGN}.input", return_value="y"):
with mock.patch(f"{OMNY_GENERAL_TOOLS}.input", return_value="y"):
result = align.find_rotation_center(sample_type="isolated")
# midpoint of (0.3,0.3) and (0.5,0.7) is (0.4, 0.5) ->
@@ -337,7 +341,7 @@ def test_find_rotation_center_isolated_declines_apply(bec_client_mock):
with mock.patch(f"{XRAY_EYE_ALIGN}.dev", dev_mock):
with mock.patch(f"{XRAY_EYE_ALIGN}.umv"):
with mock.patch(f"{XRAY_EYE_ALIGN}.time.sleep"):
with mock.patch(f"{XRAY_EYE_ALIGN}.input", return_value="n"):
with mock.patch(f"{OMNY_GENERAL_TOOLS}.input", return_value="n"):
align.find_rotation_center(sample_type="isolated")
dev_mock.lsamx.update_user_parameter.assert_not_called()
@@ -364,7 +368,7 @@ def test_find_rotation_center_extended_iterates_until_happy(bec_client_mock):
with mock.patch(f"{XRAY_EYE_ALIGN}.time.sleep"):
# first iteration: "not happy" -> second iteration: "happy",
# then accept the final apply prompt
with mock.patch(f"{XRAY_EYE_ALIGN}.input", side_effect=["n", "y", "y"]):
with mock.patch(f"{OMNY_GENERAL_TOOLS}.input", side_effect=["n", "y", "y"]):
align.find_rotation_center(sample_type="extended")
# one lamni_move_to_scan_center pair per iteration -> 2 iterations = 4 calls
@@ -546,7 +550,7 @@ def test_find_rotation_center_smear_experimental_switches_live_view_signal(bec_c
with mock.patch(f"{XRAY_EYE_ALIGN}.umv"):
with mock.patch(f"{XRAY_EYE_ALIGN}.mv", return_value=report):
with mock.patch(f"{XRAY_EYE_ALIGN}.time.sleep"):
with mock.patch(f"{XRAY_EYE_ALIGN}.input", side_effect=["y", "y"]):
with mock.patch(f"{OMNY_GENERAL_TOOLS}.input", side_effect=["y", "y"]):
with mock.patch.object(align, "_save_smear_calibration_data"):
align.find_rotation_center_smear_experimental()
@@ -572,7 +576,7 @@ def test_find_rotation_center_smear_experimental_saves_composites_and_clicks(bec
with mock.patch(f"{XRAY_EYE_ALIGN}.umv"):
with mock.patch(f"{XRAY_EYE_ALIGN}.mv", return_value=report):
with mock.patch(f"{XRAY_EYE_ALIGN}.time.sleep"):
with mock.patch(f"{XRAY_EYE_ALIGN}.input", side_effect=["y", "y"]):
with mock.patch(f"{OMNY_GENERAL_TOOLS}.input", side_effect=["y", "y"]):
with mock.patch.object(align, "_save_smear_calibration_data") as save_mock:
align.find_rotation_center_smear_experimental(sweep_deg=45.0)