From 6e6bddd2b0612555c52eb34fc8d72d375789ce9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carolina=20Villal=C3=B3n?= Date: Fri, 27 Sep 2024 13:01:43 -0300 Subject: [PATCH] Add test for error reporting in AT prepare_for_flat --- .../ts/observatory/control/auxtel/atcalsys.py | 4 +-- tests/auxtel/test_atcalsys.py | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/python/lsst/ts/observatory/control/auxtel/atcalsys.py b/python/lsst/ts/observatory/control/auxtel/atcalsys.py index e7948e84..f826d5e6 100644 --- a/python/lsst/ts/observatory/control/auxtel/atcalsys.py +++ b/python/lsst/ts/observatory/control/auxtel/atcalsys.py @@ -231,7 +231,7 @@ async def prepare_for_flat(self, sequence_name: str) -> None: task_setup_electrometer, return_exceptions=True, ) - operations = ["Setup monochromator", "Setup latiss", "Setup electrometer"] + operations = ["Setup monochromator", "Setup latiss", "Setup electrometers"] exceptions = [ (operation, value) for (operation, value) in zip(operations, return_values) @@ -241,7 +241,7 @@ async def prepare_for_flat(self, sequence_name: str) -> None: if exceptions: err_message = f"{len(exceptions)} out of {len(operations)} failed.\n" for operation, exception in exceptions: - err_message += f"{operation} failed with '{exception!r}'.\n" + err_message += f"{operation} failed with {exception!r}.\n" raise RuntimeError(err_message) async def calculate_optimized_exposure_times( diff --git a/tests/auxtel/test_atcalsys.py b/tests/auxtel/test_atcalsys.py index eec13634..5294000f 100644 --- a/tests/auxtel/test_atcalsys.py +++ b/tests/auxtel/test_atcalsys.py @@ -20,6 +20,7 @@ import asyncio import logging +import re import types import unittest.mock @@ -153,6 +154,33 @@ async def test_prepare_for_flat(self) -> None: timeout=mock_latiss.long_timeout, ) + async def test_prepare_for_flat_with_exceptions(self) -> None: + latiss_exception = RuntimeError("Error in LATISS") + monochromator_exception = RuntimeError("Error in monochromator") + electrometers_exception = RuntimeError("Error in electrometers") + + self.atcalsys.latiss = unittest.mock.AsyncMock() + self.atcalsys.latiss.setup_instrument = unittest.mock.AsyncMock( + side_effect=latiss_exception + ) + self.atcalsys.rem.atmonochromator.cmd_updateMonochromatorSetup.set_start = ( + unittest.mock.AsyncMock(side_effect=monochromator_exception) + ) + self.atcalsys.setup_electrometers = unittest.mock.AsyncMock( + side_effect=electrometers_exception + ) + + with pytest.raises( + RuntimeError, + match=re.escape( + "3 out of 3 failed.\n" + f"Setup monochromator failed with {monochromator_exception!r}.\n" + f"Setup latiss failed with {latiss_exception!r}.\n" + f"Setup electrometers failed with {electrometers_exception!r}.\n" + ), + ): + await self.atcalsys.prepare_for_flat("at_whitelight_r") + async def mock_end_readout( self, flush: bool, timeout: float ) -> types.SimpleNamespace: