Skip to content

Commit

Permalink
Move compatibility logic into its own module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 18, 2024
1 parent 1ac0d89 commit 7cf90ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tempora/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
For example, to run a job at 08:00 every morning in 'Asia/Calcutta':
>>> import zoneinfo
>>> from tests.compat.py38 import zoneinfo
>>> job = lambda: print("time is now", datetime.datetime())
>>> time = datetime.time(8, tzinfo=zoneinfo.ZoneInfo('Asia/Calcutta'))
>>> cmd = PeriodicCommandFixedDelay.daily_at(time, job)
Expand Down
14 changes: 5 additions & 9 deletions tests/test_schedule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import time
import random
import datetime
Expand All @@ -9,10 +8,7 @@

from tempora import schedule

if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo
else: # pragma: no cover
from backports.zoneinfo import ZoneInfo
from .compat.py38 import zoneinfo


do_nothing = type(None)
Expand Down Expand Up @@ -58,7 +54,7 @@ def test_command_at_noon(self):
"""
Create a periodic command that's run at noon every day.
"""
when = datetime.time(12, 0, tzinfo=ZoneInfo('UTC'))
when = datetime.time(12, 0, tzinfo=zoneinfo.ZoneInfo('UTC'))
cmd = schedule.PeriodicCommandFixedDelay.daily_at(when, target=None)
assert cmd.due() is False
next_cmd = cmd.next()
Expand All @@ -80,13 +76,13 @@ def test_command_at_noon_distant_local(self, hour, tz_offset):

class TestTimezones:
def test_alternate_timezone_west(self):
target_tz = ZoneInfo('US/Pacific')
target_tz = zoneinfo.ZoneInfo('US/Pacific')
target = schedule.now().astimezone(target_tz)
cmd = schedule.DelayedCommand.at_time(target, target=None)
assert cmd.due()

def test_alternate_timezone_east(self):
target_tz = ZoneInfo('Europe/Amsterdam')
target_tz = zoneinfo.ZoneInfo('Europe/Amsterdam')
target = schedule.now().astimezone(target_tz)
cmd = schedule.DelayedCommand.at_time(target, target=None)
assert cmd.due()
Expand All @@ -97,7 +93,7 @@ def test_daylight_savings(self):
a DST boundary.
"""
with freezegun.freeze_time('2018-03-10'):
target_tz = ZoneInfo('US/Eastern')
target_tz = zoneinfo.ZoneInfo('US/Eastern')
target_time = datetime.time(9, tzinfo=target_tz)
cmd = schedule.PeriodicCommandFixedDelay.daily_at(
target_time, target=lambda: None
Expand Down

0 comments on commit 7cf90ea

Please sign in to comment.