import io from unittest import mock import pytest from bec_ipython_client.beamline_mixin import BeamlineMixin from bec_ipython_client.plugins.SLS.sls_info import OperatorInfo, SLSInfo from rich.console import Console from csaxs_bec.bec_ipython_client.plugins.cSAXS.beamline_info import BeamlineInfo def test_bl_show_all(): mixin = BeamlineMixin() mixin._bl_info_register(SLSInfo) mixin._bl_info_register(OperatorInfo) mixin._bl_info_register(BeamlineInfo) calls = mixin._bl_calls with mock.patch.object(calls[0], "show") as sls_info: with mock.patch.object(calls[1], "show") as op_msgs: with mock.patch.object(calls[2], "show") as bl_info: mixin.bl_show_all() bl_info.assert_called_once() op_msgs.assert_called_once() sls_info.assert_called_once() @pytest.mark.parametrize( "info,out", ( [ ( { "x12sa_op_status": {"value": "attended"}, "x12sa_id_gap": {"value": 4.2}, "x12sa_storage_ring_vac": {"value": "OK"}, "x12sa_es1_shutter_status": {"value": "OPEN"}, "x12sa_mokev": {"value": 6.2002}, "x12sa_fe_status": {"value": "Open enabled"}, "x12sa_es1_valve": {"value": "open"}, "x12sa_exposure_box1_pressure": {"value": 7.975205787427068e-09}, "x12sa_exposure_box2_pressure": {"value": 7.975205787427068e-09}, }, " X12SA Info \n┌─────────────────────────┬──────────────┐\n│ Key │ Value │\n├─────────────────────────┼──────────────┤\n│ Beamline operation │ attended │\n│ ID gap │ 4.200 mm │\n│ Storage ring vacuum │ OK │\n│ Shutter │ OPEN │\n│ Selected energy (mokev) │ 6.200 keV │\n│ Front end shutter │ Open enabled │\n│ ES1 valve │ open │\n│ Exposure box 1 pressure │ 8.0e-09 mbar │\n│ Exposure box 2 pressure │ 8.0e-09 mbar │\n└─────────────────────────┴──────────────┘\n", ) ] ), ) def test_bl_info(info, out): mixin = BeamlineMixin() mixin._bl_info_register(BeamlineInfo) bl_call = mixin._bl_calls[-1] with mock.patch.object( bl_call, "_get_beamline_info_messages", return_value=info ) as get_bl_info: console = Console(file=io.StringIO(), width=120) with mock.patch.object(bl_call, "_get_console", return_value=console): mixin.bl_show_all() get_bl_info.assert_called_once() # pylint: disable=no-member output = console.file.getvalue() assert output == out