Skip to content

Commit a29852e

Browse files
committed
Remove obsolete test helpers
1 parent 90d3eeb commit a29852e

34 files changed

+178
-263
lines changed

pendulum/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@
2929
from pendulum.formatting import Formatter
3030
from pendulum.helpers import format_diff
3131
from pendulum.helpers import get_locale
32-
from pendulum.helpers import get_test_now
33-
from pendulum.helpers import has_test_now
3432
from pendulum.helpers import locale
3533
from pendulum.helpers import set_locale
36-
from pendulum.helpers import set_test_now
37-
from pendulum.helpers import test
3834
from pendulum.helpers import week_ends_at
3935
from pendulum.helpers import week_starts_at
4036
from pendulum.parser import parse
@@ -240,8 +236,7 @@ def from_format(
240236
"""
241237
Creates a DateTime instance from a specific format.
242238
"""
243-
parts = _formatter.parse(string, fmt, now(), locale=locale)
244-
239+
parts = _formatter.parse(string, fmt, now(tz=tz), locale=locale)
245240
if parts["tz"] is None:
246241
parts["tz"] = tz
247242

@@ -338,17 +333,13 @@ def period(start: DateTime, end: DateTime, absolute: bool = False) -> Period:
338333
"from_format",
339334
"from_timestamp",
340335
"get_locale",
341-
"get_test_now",
342-
"has_test_now",
343336
"instance",
344337
"local",
345338
"locale",
346339
"naive",
347340
"now",
348341
"period",
349342
"set_locale",
350-
"set_test_now",
351-
"test",
352343
"week_ends_at",
353344
"week_starts_at",
354345
"parse",

pendulum/date.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
from pendulum.constants import YEARS_PER_DECADE
2525
from pendulum.exceptions import PendulumException
2626
from pendulum.helpers import add_duration
27-
from pendulum.helpers import get_test_now
28-
from pendulum.helpers import has_test_now
2927
from pendulum.mixins.default import FormattableMixin
3028
from pendulum.period import Period
3129

@@ -733,9 +731,6 @@ def average(self, dt: date | None = None) -> Date:
733731

734732
@classmethod
735733
def today(cls) -> Date:
736-
if has_test_now():
737-
return cast(pendulum.DateTime, get_test_now()).date()
738-
739734
dt = date.today()
740735

741736
return cls(dt.year, dt.month, dt.day)

pendulum/datetime.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
from pendulum.date import Date
3333
from pendulum.exceptions import PendulumException
3434
from pendulum.helpers import add_duration
35-
from pendulum.helpers import get_test_now
36-
from pendulum.helpers import has_test_now
3735
from pendulum.period import Period
3836
from pendulum.time import Time
3937
from pendulum.tz import UTC
@@ -135,15 +133,6 @@ def now(
135133
"""
136134
Get a DateTime instance for the current date and time.
137135
"""
138-
if has_test_now():
139-
test_instance: DateTime = cast(DateTime, get_test_now())
140-
_tz = pendulum._safe_timezone(tz)
141-
142-
if tz is not None and _tz != test_instance.timezone:
143-
test_instance = test_instance.in_tz(_tz)
144-
145-
return test_instance
146-
147136
if tz is None or tz == "local":
148137
dt = datetime.datetime.now(local_timezone())
149138
elif tz is UTC or tz == "UTC":

pendulum/helpers.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import os
44
import struct
55

6-
from contextlib import contextmanager
76
from datetime import date
87
from datetime import datetime
98
from datetime import timedelta
109
from math import copysign
1110
from typing import TYPE_CHECKING
12-
from typing import Iterator
1311
from typing import TypeVar
1412
from typing import overload
1513

@@ -178,27 +176,6 @@ def _sign(x: float) -> int:
178176
# Global helpers
179177

180178

181-
@contextmanager
182-
def test(mock: pendulum.DateTime) -> Iterator[None]:
183-
set_test_now(mock)
184-
try:
185-
yield
186-
finally:
187-
set_test_now()
188-
189-
190-
def set_test_now(test_now: pendulum.DateTime | None = None) -> None:
191-
pendulum._TEST_NOW = test_now
192-
193-
194-
def get_test_now() -> pendulum.DateTime | None:
195-
return pendulum._TEST_NOW
196-
197-
198-
def has_test_now() -> bool:
199-
return pendulum._TEST_NOW is not None
200-
201-
202179
def locale(name: str) -> Locale:
203180
return Locale.load(name)
204181

@@ -238,10 +215,6 @@ def week_ends_at(wday: int) -> None:
238215
"week_day",
239216
"add_duration",
240217
"format_diff",
241-
"test",
242-
"set_test_now",
243-
"get_test_now",
244-
"has_test_now",
245218
"locale",
246219
"set_locale",
247220
"get_locale",

pendulum/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
def parse(text: str, **options: t.Any) -> Date | Time | DateTime | Duration:
2626
# Use the mock now value if it exists
27-
options["now"] = options.get("now", pendulum.get_test_now())
27+
options["now"] = options.get("now")
2828

2929
return _parse(text, **options)
3030

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def setup():
1111

1212
yield
1313

14-
pendulum.set_test_now()
1514
pendulum.set_locale("en")
1615
pendulum.set_local_timezone()
1716
pendulum.week_starts_at(pendulum.MONDAY)

tests/date/test_diff.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ def test_diff_for_humans_now_and_nearly_month(today):
129129

130130

131131
def test_diff_for_humans_now_and_month():
132-
with pendulum.test(pendulum.datetime(2016, 4, 1)):
132+
with pendulum.travel_to(pendulum.datetime(2016, 4, 1)):
133133
today = pendulum.today().date()
134134

135135
assert today.subtract(weeks=4).diff_for_humans() == "4 weeks ago"
136136
assert today.subtract(months=1).diff_for_humans() == "1 month ago"
137137

138-
with pendulum.test(pendulum.datetime(2017, 3, 1)):
138+
with pendulum.travel_to(pendulum.datetime(2017, 3, 1)):
139139
today = pendulum.today().date()
140140

141141
assert today.subtract(weeks=4).diff_for_humans() == "1 month ago"
@@ -182,23 +182,23 @@ def test_diff_for_humans_now_and_nearly_future_month(today):
182182

183183

184184
def test_diff_for_humans_now_and_future_month():
185-
with pendulum.test(pendulum.datetime(2016, 3, 1)):
185+
with pendulum.travel_to(pendulum.datetime(2016, 3, 1)):
186186
today = pendulum.today("UTC").date()
187187

188188
assert today.add(weeks=4).diff_for_humans() == "in 4 weeks"
189189
assert today.add(months=1).diff_for_humans() == "in 1 month"
190190

191-
with pendulum.test(pendulum.datetime(2017, 3, 31)):
191+
with pendulum.travel_to(pendulum.datetime(2017, 3, 31)):
192192
today = pendulum.today("UTC").date()
193193

194194
assert today.add(months=1).diff_for_humans() == "in 1 month"
195195

196-
with pendulum.test(pendulum.datetime(2017, 4, 30)):
196+
with pendulum.travel_to(pendulum.datetime(2017, 4, 30)):
197197
today = pendulum.today("UTC").date()
198198

199199
assert today.add(months=1).diff_for_humans() == "in 1 month"
200200

201-
with pendulum.test(pendulum.datetime(2017, 1, 31)):
201+
with pendulum.travel_to(pendulum.datetime(2017, 1, 31)):
202202
today = pendulum.today("UTC").date()
203203

204204
assert today.add(weeks=4).diff_for_humans() == "in 1 month"
@@ -245,23 +245,23 @@ def test_diff_for_humans_other_and_nearly_month(today):
245245

246246

247247
def test_diff_for_humans_other_and_month():
248-
with pendulum.test(pendulum.datetime(2016, 3, 1)):
248+
with pendulum.travel_to(pendulum.datetime(2016, 3, 1)):
249249
today = pendulum.today().date()
250250

251251
assert today.diff_for_humans(today.add(weeks=4)) == "4 weeks before"
252252
assert today.diff_for_humans(today.add(months=1)) == "1 month before"
253253

254-
with pendulum.test(pendulum.datetime(2017, 3, 31)):
254+
with pendulum.travel_to(pendulum.datetime(2017, 3, 31)):
255255
today = pendulum.today().date()
256256

257257
assert today.diff_for_humans(today.add(months=1)) == "1 month before"
258258

259-
with pendulum.test(pendulum.datetime(2017, 4, 30)):
259+
with pendulum.travel_to(pendulum.datetime(2017, 4, 30)):
260260
today = pendulum.today().date()
261261

262262
assert today.diff_for_humans(today.add(months=1)) == "1 month before"
263263

264-
with pendulum.test(pendulum.datetime(2017, 1, 31)):
264+
with pendulum.travel_to(pendulum.datetime(2017, 1, 31)):
265265
today = pendulum.today().date()
266266

267267
assert today.diff_for_humans(today.add(weeks=4)) == "1 month before"
@@ -308,13 +308,13 @@ def test_diff_for_humans_other_and_nearly_future_month(today):
308308

309309

310310
def test_diff_for_humans_other_and_future_month():
311-
with pendulum.test(pendulum.datetime(2016, 3, 1)):
311+
with pendulum.travel_to(pendulum.datetime(2016, 3, 1)):
312312
today = pendulum.today().date()
313313

314314
assert today.diff_for_humans(today.subtract(weeks=4)) == "4 weeks after"
315315
assert today.diff_for_humans(today.subtract(months=1)) == "1 month after"
316316

317-
with pendulum.test(pendulum.datetime(2017, 2, 28)):
317+
with pendulum.travel_to(pendulum.datetime(2017, 2, 28)):
318318
today = pendulum.today().date()
319319

320320
assert today.diff_for_humans(today.subtract(weeks=4)) == "1 month after"

tests/datetime/test_comparison.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def test_less_than_or_equal_with_timezone_false():
241241

242242

243243
def test_is_anniversary():
244-
with pendulum.test(pendulum.now()):
244+
with pendulum.travel_to(pendulum.now()):
245245
d = pendulum.now()
246246
an_anniversary = d.subtract(years=1)
247247
assert an_anniversary.is_anniversary()
@@ -258,7 +258,7 @@ def test_is_anniversary():
258258

259259

260260
def test_is_birthday(): # backward compatibility
261-
with pendulum.test(pendulum.now()):
261+
with pendulum.travel_to(pendulum.now()):
262262
d = pendulum.now()
263263
an_anniversary = d.subtract(years=1)
264264
assert an_anniversary.is_birthday()

0 commit comments

Comments
 (0)