|
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 | import pytz |
9 | | -import time_machine |
10 | 9 |
|
11 | 10 | from dateutil import tz |
12 | 11 |
|
13 | 12 | import pendulum |
14 | 13 |
|
15 | 14 | from pendulum import DateTime |
16 | 15 | from pendulum.tz import timezone |
| 16 | +from pendulum.utils._compat import PYPY |
17 | 17 | from tests.conftest import assert_datetime |
18 | 18 |
|
| 19 | +if not PYPY: |
| 20 | + import time_machine |
| 21 | +else: |
| 22 | + time_machine = None |
| 23 | + |
19 | 24 |
|
20 | 25 | @pytest.fixture(autouse=True) |
21 | 26 | def _setup(): |
@@ -105,44 +110,43 @@ def test_now(): |
105 | 110 | assert now.hour != in_paris.hour |
106 | 111 |
|
107 | 112 |
|
108 | | -@time_machine.travel("2016-03-27 00:30:00Z", tick=False) |
109 | | -def test_now_dst_off(): |
110 | | - utc = pendulum.now("UTC") |
111 | | - in_paris = pendulum.now("Europe/Paris") |
112 | | - in_paris_from_utc = utc.in_tz("Europe/Paris") |
113 | | - assert in_paris.hour == 1 |
114 | | - assert not in_paris.is_dst() |
115 | | - assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
116 | | - |
117 | | - |
118 | | -@time_machine.travel("2016-03-27 01:30:00Z", tick=False) |
119 | | -def test_now_dst_transitioning_on(): |
120 | | - utc = pendulum.now("UTC") |
121 | | - in_paris = pendulum.now("Europe/Paris") |
122 | | - in_paris_from_utc = utc.in_tz("Europe/Paris") |
123 | | - assert in_paris.hour == 3 |
124 | | - assert in_paris.is_dst() |
125 | | - assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
126 | | - |
127 | | - |
128 | | -@time_machine.travel("2016-10-30 00:30:00Z", tick=False) |
129 | | -def test_now_dst_on(): |
130 | | - utc = pendulum.now("UTC") |
131 | | - in_paris = pendulum.now("Europe/Paris") |
132 | | - in_paris_from_utc = utc.in_tz("Europe/Paris") |
133 | | - assert in_paris.hour == 2 |
134 | | - assert in_paris.is_dst() |
135 | | - assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
136 | | - |
137 | | - |
138 | | -@time_machine.travel("2016-10-30 01:30:00Z", tick=False) |
139 | | -def test_now_dst_transitioning_off(): |
140 | | - utc = pendulum.now("UTC") |
141 | | - in_paris = pendulum.now("Europe/Paris") |
142 | | - in_paris_from_utc = utc.in_tz("Europe/Paris") |
143 | | - assert in_paris.hour == 2 |
144 | | - assert not in_paris.is_dst() |
145 | | - assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 113 | +if time_machine: |
| 114 | + |
| 115 | + @time_machine.travel("2016-03-27 00:30:00Z", tick=False) |
| 116 | + def test_now_dst_off(): |
| 117 | + utc = pendulum.now("UTC") |
| 118 | + in_paris = pendulum.now("Europe/Paris") |
| 119 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 120 | + assert in_paris.hour == 1 |
| 121 | + assert not in_paris.is_dst() |
| 122 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 123 | + |
| 124 | + @time_machine.travel("2016-03-27 01:30:00Z", tick=False) |
| 125 | + def test_now_dst_transitioning_on(): |
| 126 | + utc = pendulum.now("UTC") |
| 127 | + in_paris = pendulum.now("Europe/Paris") |
| 128 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 129 | + assert in_paris.hour == 3 |
| 130 | + assert in_paris.is_dst() |
| 131 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 132 | + |
| 133 | + @time_machine.travel("2016-10-30 00:30:00Z", tick=False) |
| 134 | + def test_now_dst_on(): |
| 135 | + utc = pendulum.now("UTC") |
| 136 | + in_paris = pendulum.now("Europe/Paris") |
| 137 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 138 | + assert in_paris.hour == 2 |
| 139 | + assert in_paris.is_dst() |
| 140 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 141 | + |
| 142 | + @time_machine.travel("2016-10-30 01:30:00Z", tick=False) |
| 143 | + def test_now_dst_transitioning_off(): |
| 144 | + utc = pendulum.now("UTC") |
| 145 | + in_paris = pendulum.now("Europe/Paris") |
| 146 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 147 | + assert in_paris.hour == 2 |
| 148 | + assert not in_paris.is_dst() |
| 149 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
146 | 150 |
|
147 | 151 |
|
148 | 152 | def test_now_with_fixed_offset(): |
|
0 commit comments