Skip to content

Commit

Permalink
Add specific tests for reducer status format helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwartzentruber committed May 30, 2024
1 parent bc2fd56 commit cdf29f4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion grizzly/common/status_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def _format_duration(duration: Optional[int], total: float = 0) -> str:
result = ""
if duration is not None:
if total == 0:
percent = 0 # pragma: no cover
percent = 0
else:
percent = int(100 * duration / total)
result = _format_seconds(duration)
Expand Down
46 changes: 46 additions & 0 deletions grizzly/common/test_status_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
ReductionStatusReporter,
StatusReporter,
TracebackReport,
_format_duration,
_format_number,
_format_seconds,
main,
)

Expand Down Expand Up @@ -773,3 +776,46 @@ def test_main_04(mocker, tmp_path, report_type):
assert b"Runtime" not in dump_file.read_bytes()
else:
assert b"Timestamp" not in dump_file.read_bytes()


@mark.parametrize(
"value, expected",
[
(0, "0s"),
(100, "1:40"),
(3600, "1:00:00"),
],
)
def test_format_seconds(value, expected):
"""test _format_seconds used by TableFormatter"""
assert _format_seconds(value) == expected


@mark.parametrize(
"value, total, expected",
[
(None, 0, ""),
(0, 0, "0s ( 0%)"),
(100, 0, "1:40 ( 0%)"),
(100, 200, "1:40 ( 50%)"),
(3600, 3600, "1:00:00 (100%)"),
],
)
def test_format_duration(value, total, expected):
"""test _format_duration used by TableFormatter"""
assert _format_duration(value, total) == expected


@mark.parametrize(
"value, total, expected",
[
(None, 0, ""),
(0, 0, "0 ( 0%)"),
(100, 0, "100 ( 0%)"),
(100, 200, "100 ( 50%)"),
(3600, 3600, "3600 (100%)"),
],
)
def test_format_number(value, total, expected):
"""test _format_number used by TableFormatter"""
assert _format_number(value, total) == expected

0 comments on commit cdf29f4

Please sign in to comment.