From 37cd4c19e722dde693e6ef24bde67168623baf8b Mon Sep 17 00:00:00 2001 From: Relm-Arrowny Date: Fri, 29 Nov 2024 14:41:53 +0000 Subject: [PATCH] added extra info for set error --- src/dodal/devices/current_amplifiers/femto.py | 6 +++++- src/dodal/devices/current_amplifiers/sr570.py | 6 +++++- tests/devices/unit_tests/current_amplifier/test_SR570.py | 8 +++++++- tests/devices/unit_tests/current_amplifier/test_femto.py | 7 ++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/dodal/devices/current_amplifiers/femto.py b/src/dodal/devices/current_amplifiers/femto.py index e1219c6ab6..3be494c17e 100644 --- a/src/dodal/devices/current_amplifiers/femto.py +++ b/src/dodal/devices/current_amplifiers/femto.py @@ -92,7 +92,11 @@ def __init__( @AsyncStatus.wrap async def set(self, value) -> None: if value not in [item.value for item in self.gain_conversion_table]: - raise ValueError(f"Gain value {value} is not within {self.name} range.") + raise ValueError( + f"Gain value {value} is not within {self.name} range." + + "\n Available gain:" + + f" {[f'{c.value:.0e}' for c in self.gain_conversion_table]}" + ) sen_setting = self.gain_conversion_table(value).name LOGGER.info(f"{self.name} gain change to {sen_setting}:{value}") diff --git a/src/dodal/devices/current_amplifiers/sr570.py b/src/dodal/devices/current_amplifiers/sr570.py index 172a1347d1..a75a02d06f 100644 --- a/src/dodal/devices/current_amplifiers/sr570.py +++ b/src/dodal/devices/current_amplifiers/sr570.py @@ -157,7 +157,11 @@ def __init__( @AsyncStatus.wrap async def set(self, value) -> None: if value not in [item.value for item in self.gain_conversion_table]: - raise ValueError(f"Gain value {value} is not within {self.name} range.") + raise ValueError( + f"Gain value {value} is not within {self.name} range." + + "\n Available gain:" + + f" {[f'{c.value:.0e}' for c in self.gain_conversion_table]}" + ) sen_setting = self.gain_conversion_table(value).name LOGGER.info(f"{self.name} gain change to {value}") diff --git a/tests/devices/unit_tests/current_amplifier/test_SR570.py b/tests/devices/unit_tests/current_amplifier/test_SR570.py index 97f2d38b7d..26909eba14 100644 --- a/tests/devices/unit_tests/current_amplifier/test_SR570.py +++ b/tests/devices/unit_tests/current_amplifier/test_SR570.py @@ -114,7 +114,13 @@ async def test_sr570_set( async def test_sr570_set_fail_out_of_range(sleep: AsyncMock, mock_sr570: SR570, gain): with pytest.raises(ValueError) as e: await mock_sr570.set(gain) - assert str(e.value) == f"Gain value {gain} is not within {mock_sr570.name} range." + + assert ( + str(e.value) + == f"Gain value {gain} is not within {mock_sr570.name} range." + + "\n Available gain:" + + f" {[f'{c.value:.0e}' for c in mock_sr570.gain_conversion_table]}" + ) sleep.assert_not_called() diff --git a/tests/devices/unit_tests/current_amplifier/test_femto.py b/tests/devices/unit_tests/current_amplifier/test_femto.py index 58f3e78c15..25c8d2e889 100644 --- a/tests/devices/unit_tests/current_amplifier/test_femto.py +++ b/tests/devices/unit_tests/current_amplifier/test_femto.py @@ -114,7 +114,12 @@ async def test_femto_set_fail_out_of_range( ): with pytest.raises(ValueError) as e: await mock_femto.set(gain) - assert str(e.value) == f"Gain value {gain} is not within {mock_femto.name} range." + assert ( + str(e.value) + == f"Gain value {gain} is not within {mock_femto.name} range." + + "\n Available gain:" + + f" {[f'{c.value:.0e}' for c in mock_femto.gain_conversion_table]}" + ) get_mock_put(mock_femto.gain).assert_not_called() sleep.assert_not_called()