aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shirayuki Nekomata <[email protected]>2019-12-05 00:45:36 +0700
committerGravatar Shirayuki Nekomata <[email protected]>2019-12-05 00:45:36 +0700
commitccdd8363d75846f0841791ba54763dae28243c62 (patch)
tree3a9e883c4268e2bd7e10afa9a2969c4d3b6d5535
parentChanged `assert` to `self.assertIs` for `test_wait_until` (diff)
Splitting test cases for `format_infraction_with_duration` into proper, independent tests.
-rw-r--r--tests/bot/utils/test_time.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/tests/bot/utils/test_time.py b/tests/bot/utils/test_time.py
index 0afabe400..2a2a707d8 100644
--- a/tests/bot/utils/test_time.py
+++ b/tests/bot/utils/test_time.py
@@ -37,7 +37,7 @@ class TimeTests(unittest.TestCase):
for delta, precision, max_units, expected in test_cases:
self.assertEqual(time.humanize_delta(delta, precision, max_units), expected)
- def test_humanize_delta_should_work_normally(self):
+ def test_humanize_delta_should_normal_usage(self):
"""Testing humanize delta."""
test_cases = (
(relativedelta(days=2), 'seconds', 1, '2 days'),
@@ -78,18 +78,38 @@ class TimeTests(unittest.TestCase):
mock.assert_called_once_with(10 * 60)
- def test_format_infraction_with_duration(self):
- """Testing format_infraction_with_duration."""
+ def test_format_infraction_with_duration_none_expiry(self):
+ """format_infraction_with_duration should work for None expiry."""
+ self.assertEqual(time.format_infraction_with_duration(None), None)
+
+ # To make sure that date_from and max_units are not touched
+ self.assertEqual(time.format_infraction_with_duration(None, date_from='Why hello there!'), None)
+ self.assertEqual(time.format_infraction_with_duration(None, max_units=float('inf')), None)
+ self.assertEqual(
+ time.format_infraction_with_duration(None, date_from='Why hello there!', max_units=float('inf')),
+ None
+ )
+
+ def test_format_infraction_with_duration_custom_units(self):
+ """format_infraction_with_duration should work for custom max_units."""
+ self.assertEqual(
+ time.format_infraction_with_duration('2019-12-12T00:01:00Z', datetime(2019, 12, 11, 12, 5, 5), 6),
+ '2019-12-12 00:01 (11 hours, 55 minutes and 55 seconds)'
+ )
+
+ self.assertEqual(
+ time.format_infraction_with_duration('2019-11-23T20:09:00Z', datetime(2019, 4, 25, 20, 15), 20),
+ '2019-11-23 20:09 (6 months, 28 days, 23 hours and 54 minutes)'
+ )
+
+ def test_format_infraction_with_duration_normal_usage(self):
+ """format_infraction_with_duration should work for normal usage, across various durations."""
test_cases = (
('2019-12-12T00:01:00Z', datetime(2019, 12, 11, 12, 0, 5), 2, '2019-12-12 00:01 (12 hours and 55 seconds)'),
('2019-12-12T00:01:00Z', datetime(2019, 12, 11, 12, 0, 5), 1, '2019-12-12 00:01 (12 hours)'),
- ('2019-12-12T00:01:00Z', datetime(2019, 12, 11, 12, 5, 5), 6,
- '2019-12-12 00:01 (11 hours, 55 minutes and 55 seconds)'),
('2019-12-12T00:00:00Z', datetime(2019, 12, 11, 23, 59), 2, '2019-12-12 00:00 (1 minute)'),
('2019-11-23T20:09:00Z', datetime(2019, 11, 15, 20, 15), 2, '2019-11-23 20:09 (7 days and 23 hours)'),
('2019-11-23T20:09:00Z', datetime(2019, 4, 25, 20, 15), 2, '2019-11-23 20:09 (6 months and 28 days)'),
- ('2019-11-23T20:09:00Z', datetime(2019, 4, 25, 20, 15), 6,
- '2019-11-23 20:09 (6 months, 28 days, 23 hours and 54 minutes)'),
('2019-11-23T20:58:00Z', datetime(2019, 11, 23, 20, 53), 2, '2019-11-23 20:58 (5 minutes)'),
('2019-11-24T00:00:00Z', datetime(2019, 11, 23, 23, 59, 0), 2, '2019-11-24 00:00 (1 minute)'),
('2019-11-23T23:59:00Z', datetime(2017, 7, 21, 23, 0), 2, '2019-11-23 23:59 (2 years and 4 months)'),