-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathtest_strict_parse.py
More file actions
105 lines (61 loc) · 2.3 KB
/
test_strict_parse.py
File metadata and controls
105 lines (61 loc) · 2.3 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
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
100
101
102
103
104
105
from __future__ import annotations
import pytest
from pendulum.parser import parse_date
from pendulum.parser import parse_datetime
from pendulum.parser import parse_duration
from pendulum.parser import parse_time
# tests for parse_datetime
def test_parse_datetime_valid() -> None:
dt = parse_datetime("2026-03-19T11:28:37")
assert dt.year == 2026
def test_parse_datetime_accepts_date() -> None:
dt = parse_datetime("2026-03-19")
assert dt.hour == 0
def test_parse_datetime_rejects_duration() -> None:
with pytest.raises(ValueError):
parse_datetime("PT2H")
def test_parse_datetime_rejects_interval() -> None:
with pytest.raises(ValueError):
parse_datetime("2026-03-19T12:00:00/2026-03-19T13:00:00")
def test_parse_datetime_accepts_only_year() -> None:
dt = parse_datetime("2026")
assert dt.year == 2026
# tests for parse_date
def test_parse_date_valid() -> None:
d = parse_date("2026-03-19")
assert d.day == 19
def test_parse_date_accepts_datetime() -> None:
d = parse_date("2026-03-19T11:28:37")
assert d.day == 19
def test_parse_date_rejects_time() -> None:
with pytest.raises(ValueError):
parse_date("11:28:37")
def test_parse_date_rejects_duration() -> None:
with pytest.raises(ValueError):
parse_date("PT2H")
def test_parse_date_rejects_intervals() -> None:
with pytest.raises(ValueError):
parse_date("2026-03-19T12:00:00/2026-03-19T13:00:00")
# tests for parse_time
def test_parse_time_valid() -> None:
t = parse_time("11:28:37")
assert t.hour == 11
def test_parse_time_accepts_datetime() -> None:
t = parse_time("2026-03-19T11:28:37")
assert t.minute == 28
def test_parse_time_rejects_date() -> None:
with pytest.raises(ValueError):
parse_time("2026-03-19")
def test_parse_time_rejects_duration() -> None:
with pytest.raises(ValueError):
parse_time("PT2H")
def test_parse_time_rejects_interval() -> None:
with pytest.raises(ValueError):
parse_time("2026-03-19T12:00:00/2026-03-19T13:00:00")
# tests for parse_duration
def test_parse_duration_valid() -> None:
dur = parse_duration("PT2H")
assert dur.hours == 2
def test_parse_duration_rejects_datetime() -> None:
with pytest.raises(ValueError):
parse_duration("2026-03-19T11:28:37")