File: test_datetime_timezone.py

package info (click to toggle)
python-inline-snapshot 0.32.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,900 kB
  • sloc: python: 11,339; makefile: 40; sh: 36
file content (142 lines) | stat: -rw-r--r-- 3,325 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from inline_snapshot import snapshot
from inline_snapshot.testing import Example


def test_datetime_with_timezone():
    Example(
        {
            "test_something.py": """\
from datetime import datetime, timezone
from inline_snapshot import snapshot


def test_datetime():
    dt = datetime(2026, 2, 16, 5, 0, tzinfo=timezone.utc)
    assert dt == snapshot()
""",
        }
    ).run_inline(
        ["--inline-snapshot=create"],
        changed_files=snapshot(
            {
                "test_something.py": """\
from datetime import datetime, timezone
from inline_snapshot import snapshot


def test_datetime():
    dt = datetime(2026, 2, 16, 5, 0, tzinfo=timezone.utc)
    assert dt == snapshot(datetime(2026, 2, 16, hour=5, tzinfo=timezone.utc))
"""
            }
        ),
    ).run_inline()


def test_time_with_timezone():
    Example(
        {
            "test_something.py": """\
from datetime import time, timezone
from inline_snapshot import snapshot


def test_time():
    t = time(12, 30, tzinfo=timezone.utc)
    assert t == snapshot()
""",
        }
    ).run_inline(
        ["--inline-snapshot=create"],
        changed_files=snapshot(
            {
                "test_something.py": """\
from datetime import time, timezone
from inline_snapshot import snapshot


def test_time():
    t = time(12, 30, tzinfo=timezone.utc)
    assert t == snapshot(time(hour=12, minute=30, tzinfo=timezone.utc))
"""
            }
        ),
    ).run_inline()


def test_custom_timezone_with_offset_only():
    Example(
        {
            "test_something.py": """\
from datetime import datetime, timedelta, timezone
from inline_snapshot import snapshot


def test_custom_tz():
    tz = timezone(timedelta(hours=5))
    dt = datetime(2026, 2, 16, 5, 0, tzinfo=tz)
    assert dt == snapshot()
""",
        }
    ).run_inline(
        ["--inline-snapshot=create"],
        changed_files=snapshot(
            {
                "test_something.py": """\
from datetime import datetime, timedelta, timezone
from inline_snapshot import snapshot


def test_custom_tz():
    tz = timezone(timedelta(hours=5))
    dt = datetime(2026, 2, 16, 5, 0, tzinfo=tz)
    assert dt == snapshot(
        datetime(
            2026, 2, 16, hour=5, tzinfo=timezone(timedelta(seconds=18000), "UTC+05:00")
        )
    )
"""
            }
        ),
    ).run_inline()


def test_custom_timezone_with_name():
    Example(
        {
            "test_something.py": """\
from datetime import datetime, timedelta, timezone
from inline_snapshot import snapshot


def test_custom_tz_named():
    tz = timezone(timedelta(hours=-5), "EST")
    dt = datetime(2026, 2, 16, 5, 0, tzinfo=tz)
    assert dt == snapshot()
""",
        }
    ).run_inline(
        ["--inline-snapshot=create"],
        changed_files=snapshot(
            {
                "test_something.py": """\
from datetime import datetime, timedelta, timezone
from inline_snapshot import snapshot


def test_custom_tz_named():
    tz = timezone(timedelta(hours=-5), "EST")
    dt = datetime(2026, 2, 16, 5, 0, tzinfo=tz)
    assert dt == snapshot(
        datetime(
            2026,
            2,
            16,
            hour=5,
            tzinfo=timezone(timedelta(days=-1, seconds=68400), "EST"),
        )
    )
"""
            }
        ),
    ).run_inline()