Skip to content

Commit

Permalink
Add test for error reporting in AT prepare_for_flat
Browse files Browse the repository at this point in the history
  • Loading branch information
cvillalon committed Sep 27, 2024
1 parent 180d1c5 commit 6e6bddd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/lsst/ts/observatory/control/auxtel/atcalsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions tests/auxtel/test_atcalsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import asyncio
import logging
import re
import types
import unittest.mock

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6e6bddd

Please sign in to comment.