-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_datetime_utils.py
More file actions
43 lines (27 loc) · 1014 Bytes
/
test_datetime_utils.py
File metadata and controls
43 lines (27 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Tests for utils/datetime_utils.py"""
from datetime import datetime, timezone
from utils.datetime_utils import now_utc, parse_date, humanize_delta, timestamp_ms
def test_now_utc_is_aware():
dt = now_utc()
assert dt.tzinfo is not None
assert dt.tzinfo == timezone.utc
def test_parse_date_returns_aware():
dt = parse_date("2024-01-15")
assert dt.year == 2024
assert dt.month == 1
assert dt.day == 15
assert dt.tzinfo == timezone.utc
def test_humanize_delta_seconds_only():
assert humanize_delta(45) == "45s"
def test_humanize_delta_minutes_and_seconds():
assert humanize_delta(90) == "1m 30s"
def test_humanize_delta_hours():
assert humanize_delta(3661) == "1h 1m 1s"
def test_humanize_delta_exact_hour():
assert humanize_delta(3600) == "1h"
def test_humanize_delta_zero():
assert humanize_delta(0) == "0s"
def test_timestamp_ms_is_int():
ts = timestamp_ms()
assert isinstance(ts, int)
assert ts > 1_700_000_000_000 # after Nov 2023