Skip to content

Commit 5dfee4b

Browse files
committed
Add tests defining desired behavior for precisedelta.
1 parent efcbaf6 commit 5dfee4b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/test_time.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,28 @@ def test_precisedelta_multiple_units(
541541
(dt.timedelta(days=5, hours=4, seconds=30 * 60), "days", "%0.2f", "5.19 days"),
542542
(dt.timedelta(days=120), "months", "%0.2f", "3.93 months"),
543543
(dt.timedelta(days=183), "years", "%0.1f", "0.5 years"),
544+
(0.01, "seconds", "%0.3f", "0.010 seconds"),
545+
(31, "minutes", "%d", "1 minute"),
546+
(60 + 29.99, "minutes", "%d", "1 minute"),
547+
(60 + 30, "minutes", "%d", "2 minutes"),
548+
(60 * 60 + 30.99, "minutes", "%.0f", "1 hour"),
549+
(60 * 60 + 31, "minutes", "%.0f", "1 hour and 1 minute"),
550+
(
551+
ONE_DAY - MILLISECONDS_1_337,
552+
"seconds",
553+
"%.1f",
554+
"23 hours, 59 minutes and 58.7 seconds"
555+
),
556+
(
557+
ONE_DAY - ONE_MILLISECOND,
558+
"seconds",
559+
"%.4f",
560+
"23 hours, 59 minutes and 59.9990 seconds"
561+
),
544562
],
545563
)
546564
def test_precisedelta_custom_format(
547-
val: dt.timedelta, min_unit: str, fmt: str, expected: str
565+
val: int | float | dt.timedelta, min_unit: str, fmt: str, expected: str
548566
) -> None:
549567
assert humanize.precisedelta(val, minimum_unit=min_unit, format=fmt) == expected
550568

0 commit comments

Comments
 (0)