Skip to content

Commit

Permalink
added extra info for set error
Browse files Browse the repository at this point in the history
  • Loading branch information
Relm-Arrowny committed Nov 29, 2024
1 parent 4d54c63 commit 37cd4c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/dodal/devices/current_amplifiers/femto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
6 changes: 5 additions & 1 deletion src/dodal/devices/current_amplifiers/sr570.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
8 changes: 7 additions & 1 deletion tests/devices/unit_tests/current_amplifier/test_SR570.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
7 changes: 6 additions & 1 deletion tests/devices/unit_tests/current_amplifier/test_femto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 37cd4c1

Please sign in to comment.