Skip to content

Commit cbfb317

Browse files
committed
Improve lifetime validation exception
The message now includes the problematic values. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 8c21744 commit cbfb317

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/frequenz/client/microgrid/_lifetime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class Lifetime:
3333
def __post_init__(self) -> None:
3434
"""Validate this lifetime."""
3535
if self.start is not None and self.end is not None and self.start > self.end:
36-
raise ValueError("Start must be before or equal to end.")
36+
raise ValueError(
37+
f"Start ({self.start}) must be before or equal to end ({self.end})"
38+
)
3739

3840
def is_operational_at(self, timestamp: datetime) -> bool:
3941
"""Check whether this lifetime is active at a specific timestamp."""

tests/test_lifetime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def test_validation(
200200
)
201201

202202
if should_fail:
203-
with pytest.raises(ValueError, match="Start must be before or equal to end."):
203+
with pytest.raises(
204+
ValueError, match=r"Start \(.*\) must be before or equal to end \(.*\)"
205+
):
204206
Lifetime(start=start_time, end=end_time)
205207
else:
206208
lifetime = Lifetime(start=start_time, end=end_time)

0 commit comments

Comments
 (0)