-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathtest_in_methods.py
More file actions
52 lines (35 loc) · 1.33 KB
/
test_in_methods.py
File metadata and controls
52 lines (35 loc) · 1.33 KB
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
import pytest
import pendulum
def test_in_weeks():
it = pendulum.duration(days=17)
assert it.in_weeks() == 2
def test_in_days():
it = pendulum.duration(days=3)
assert it.in_days() == 3
def test_in_hours():
it = pendulum.duration(days=3, minutes=72)
assert it.in_hours() == 73
def test_in_minutes():
it = pendulum.duration(minutes=6, seconds=72)
assert it.in_minutes() == 7
def test_in_seconds():
it = pendulum.duration(seconds=72)
assert it.in_seconds() == 72
@pytest.mark.parametrize("month", range(1, 13))
def test_in_months_one_year_less_a_day(month):
start = pendulum.datetime(2022, month, 2).date()
end = pendulum.datetime(2023, month, 1).date() # One year less a day
assert (end - start).in_months() == 11
@pytest.mark.parametrize("month", range(1, 13))
def test_in_months_one_year(month):
start = pendulum.datetime(2022, month, 1).date()
end = pendulum.datetime(2023, month, 1).date() # One year exactly
assert (end - start).in_months() == 12
@pytest.mark.parametrize("day", range(1, 29))
def test_in_months_february(day):
start = pendulum.datetime(2022, 2, 4).date()
end_1 = pendulum.datetime(2023, 2, day).date()
end_2 = end_1.add(days=1)
m_diff_1 = (end_1 - start).in_months()
m_diff_2 = (end_2 - start).in_months()
assert m_diff_1 <= m_diff_2