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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import pendulum
import pytest
@pytest.fixture(autouse=True)
def setup():
pendulum.set_local_timezone(pendulum.timezone("America/Toronto"))
yield
pendulum.set_test_now()
pendulum.set_locale("en")
pendulum.set_local_timezone()
pendulum.week_starts_at(pendulum.MONDAY)
pendulum.week_ends_at(pendulum.SUNDAY)
def assert_datetime(
d, year, month, day, hour=None, minute=None, second=None, microsecond=None
):
assert year == d.year
assert month == d.month
assert day == d.day
if hour is not None:
assert hour == d.hour
if minute is not None:
assert minute == d.minute
if second is not None:
assert second == d.second
if microsecond is not None:
assert microsecond == d.microsecond
def assert_date(d, year, month, day):
assert year == d.year
assert month == d.month
assert day == d.day
def assert_time(t, hour, minute, second, microsecond=None):
assert hour == t.hour
assert minute == t.minute
assert second == t.second
if microsecond is not None:
assert microsecond == t.microsecond
def assert_duration(
dur,
years=None,
months=None,
weeks=None,
days=None,
hours=None,
minutes=None,
seconds=None,
microseconds=None,
):
expected = {}
actual = {}
if years is not None:
expected["years"] = dur.years
actual["years"] = years
if months is not None:
expected["months"] = dur.months
actual["months"] = months
if weeks is not None:
expected["weeks"] = dur.weeks
actual["weeks"] = weeks
if days is not None:
expected["days"] = dur.remaining_days
actual["days"] = days
if hours is not None:
expected["hours"] = dur.hours
actual["hours"] = hours
if minutes is not None:
expected["minutes"] = dur.minutes
actual["minutes"] = minutes
if seconds is not None:
expected["seconds"] = dur.remaining_seconds
actual["seconds"] = seconds
if microseconds is not None:
expected["microseconds"] = dur.microseconds
actual["microseconds"] = microseconds
assert expected == actual
|