Skip to content

Commit

Permalink
multiple_of to raise ValueError instead of RuntimeError
Browse files Browse the repository at this point in the history
  • Loading branch information
markheik committed Apr 17, 2023
1 parent ae22504 commit 8e931ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/zhinst/toolkit/driver/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def multiple_of(value: float, factor: float, rounding: str) -> float:
Returns:
Rounded value.
.. versionchanged:: 0.5.3
Invalid `rounding` value raises `ValueError` instead of `RuntimeError`.
"""
if abs(round(value / factor) * factor - value) < 1e-12:
return value
Expand All @@ -117,7 +121,7 @@ def multiple_of(value: float, factor: float, rounding: str) -> float:
f"multiple: {v_rounded:.3e}",
)
return v_rounded
raise RuntimeError(
raise ValueError(
f"Invalid rounding type {rounding} only the "
"following values are allowed: [nearest,down]"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def test_multiple_of(self, caplog):
assert len(caplog.records) == 2
assert Parse.multiple_of(12, 6, "down") == 12
assert len(caplog.records) == 2
with pytest.raises(RuntimeError):
with pytest.raises(ValueError):
Parse.multiple_of(100, 6, "up")

0 comments on commit 8e931ce

Please sign in to comment.