From 518c0ecd56229ee3ce4624b62993dbb62626f196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 13 Oct 2023 17:01:33 +0200 Subject: [PATCH] Add more time tests for fractional numbers --- tests/test_time.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_time.py b/tests/test_time.py index 907a800..860475c 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -6,7 +6,6 @@ from common.time import format_duration class FormatDurationTest(unittest.TestCase): def setUp(self) -> None: - return super().setUp() def test_only_days(self): @@ -19,6 +18,21 @@ class FormatDurationTest(unittest.TestCase): result = format_duration(delta, "%H hours") self.assertEqual(result, "1 hours") + def test_only_hours_fractional(self): + delta = timedelta(hours=1) + result = format_duration(delta, "%.1H hours") + self.assertEqual(result, "1.0 hours") + + def test_less_than_hour_with_precision(self): + delta = timedelta(hours=0.5) + result = format_duration(delta, "%.1H hours") + self.assertEqual(result, "0.5 hours") + + def test_less_than_hour_without_precision(self): + delta = timedelta(hours=0.5) + result = format_duration(delta, "%H hours") + self.assertEqual(result, "0 hours") + def test_overflow_hours(self): delta = timedelta(hours=25) result = format_duration(delta, "%H hours")