From e566c7f982ee519a5ec3e350cef349c3238eebae Mon Sep 17 00:00:00 2001 From: appel_c Date: Wed, 29 May 2024 15:20:18 +0200 Subject: [PATCH] fix: fixed psi_detector_base to allow init with mocked device_manager --- .../base_classes/psi_detector_base.py | 10 ++++++++-- tests/test_simulation.py | 18 ++++-------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ophyd_devices/interfaces/base_classes/psi_detector_base.py b/ophyd_devices/interfaces/base_classes/psi_detector_base.py index 816be92..6f643db 100644 --- a/ophyd_devices/interfaces/base_classes/psi_detector_base.py +++ b/ophyd_devices/interfaces/base_classes/psi_detector_base.py @@ -219,11 +219,17 @@ class PSIDetectorBase(Device): self.scaninfo.load_scan_metadata() def _update_service_config(self) -> None: - """Update service config from BEC service config""" + """Update service config from BEC service config + + If bec services are not running and SERVICE_CONFIG is NONE, we fall back to the current directory. + """ # pylint: disable=import-outside-toplevel from bec_lib.bec_service import SERVICE_CONFIG - self.service_cfg = SERVICE_CONFIG.config["service_config"]["file_writer"] + if SERVICE_CONFIG: + self.service_cfg = SERVICE_CONFIG.config["service_config"]["file_writer"] + return + self.service_cfg = {"base_path": os.path.abspath(".")} def check_scan_id(self) -> None: """Checks if scan_id has changed and set stopped flagged to True if it has.""" diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 570ab8a..185b847 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -43,20 +43,10 @@ def monitor(name="monitor"): def camera(name="camera"): """Fixture for SimCamera.""" dm = DMMock() - with ( - mock.patch( - "ophyd_devices.interfaces.base_classes.psi_detector_base.PSIDetectorBase._update_service_config", - mock.MagicMock(), - ) as mock_update_service_config, - mock.patch( - "ophyd_devices.interfaces.base_classes.psi_detector_base.PSIDetectorBase._update_filewriter", - mock.MagicMock(), - ) as mock_update_filewriter, - ): - cam = SimCamera(name=name, device_manager=dm) - cam.filewriter = mock.MagicMock() - cam.filewriter.compile_full_filename.return_value = "" - yield cam + cam = SimCamera(name=name, device_manager=dm) + cam.filewriter = mock.MagicMock() + cam.filewriter.compile_full_filename.return_value = "" + yield cam @pytest.fixture(scope="function")