-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.py
81 lines (75 loc) · 1.79 KB
/
test_utils.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import pytest
from utils import (
_round_datetime,
_round_interval,
parse_date,
parse_interval,
human_interval_str,
)
from datetime import datetime, timedelta, date
@pytest.mark.parametrize(
"message,input,expected",
[
(
"round down",
datetime(2024, 1, 2, 10, 20, 1),
datetime(2024, 1, 2, 10, 20, 0),
),
(
"round up",
datetime(2024, 1, 2, 10, 20, 31),
datetime(2024, 1, 2, 10, 21, 0),
),
(
"no round needed",
datetime(2024, 1, 2, 10, 20),
datetime(2024, 1, 2, 10, 20, 0),
),
],
)
def test__round_datetime(
message: str,
input: datetime,
expected: datetime,
):
assert _round_datetime(input) == expected, message
@pytest.mark.parametrize(
"input,expected",
[
(
"today",
_round_datetime(datetime.now().astimezone()),
),
(
"1 month",
_round_datetime(
datetime.now().replace(month=date.today().month + 1)
).astimezone(),
),
],
)
def test_parse_date(input: str, expected: datetime):
assert parse_date(input) == expected
@pytest.mark.parametrize(
"input,expected",
[
(
timedelta(days=2),
"2 days",
),
(
timedelta(minutes=25),
"25 minutes",
),
(
timedelta(days=7),
"7 days",
),
(timedelta(weeks=4), "28 days"),
(timedelta(days=61), "2 months"),
(timedelta(days=30), "30 days"),
(timedelta(days=31), "1 month and 0 days"),
],
)
def test_human_interval_str(input: timedelta, expected: str):
assert human_interval_str(input) == expected