Skip to content

Commit

Permalink
adds unit test for negative timespan
Browse files Browse the repository at this point in the history
  • Loading branch information
thl-cmk authored Jun 17, 2023
1 parent edc1881 commit 834505e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/unit/cmk/base/api/agent_based/test_render_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,22 @@ def test_timespan(seconds: float, output: str) -> None:
assert output == render.timespan(seconds=seconds)


def test_timespan_negative() -> None:
with pytest.raises(ValueError):
_ = render.timespan(seconds=-1.0)
@pytest.mark.parametrize(
"seconds, output",
[
(-0, "0 seconds"),
(-0.00000001, "-10 nanoseconds"),
(-5.3991e-05, "-54 microseconds"),
(-0.1, "-100 milliseconds"),
(-22, "-22 seconds"),
(-158, "-2 minutes 38 seconds"),
(-98, "-1 minute 38 seconds"),
(-1234567, "-14 days 6 hours"),
(-31536001, "-1 year 0 days"),
],
)
def test_timespan_negative(seconds: float, output: str) -> None:
assert output == render.timespan(seconds=seconds)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 834505e

Please sign in to comment.