try fixing jobqueue tests

This commit is contained in:
Hinrich Mahler 2024-12-30 22:17:51 +01:00
parent 37dfdf8b8a
commit ad4d460591

View file

@ -18,6 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import asyncio import asyncio
import calendar import calendar
import contextlib
import datetime as dtm import datetime as dtm
import logging import logging
import platform import platform
@ -77,6 +78,13 @@ class TestJobQueue:
job_time = 0 job_time = 0
received_error = None received_error = None
@staticmethod
def normalize(datetime: dtm.datetime, timezone: dtm.tzinfo) -> dtm.datetime:
with contextlib.suppress(AttributeError):
return timezone.normalize(datetime)
return datetime
async def test_repr(self, app): async def test_repr(self, app):
jq = JobQueue() jq = JobQueue()
jq.set_application(app) jq.set_application(app)
@ -400,7 +408,7 @@ class TestJobQueue:
if day > next_months_days: if day > next_months_days:
expected_reschedule_time += dtm.timedelta(next_months_days) expected_reschedule_time += dtm.timedelta(next_months_days)
expected_reschedule_time = timezone.normalize(expected_reschedule_time) expected_reschedule_time = self.normalize(expected_reschedule_time, timezone)
# Adjust the hour for the special case that between now and next month a DST switch happens # Adjust the hour for the special case that between now and next month a DST switch happens
expected_reschedule_time += dtm.timedelta( expected_reschedule_time += dtm.timedelta(
hours=time_of_day.hour - expected_reschedule_time.hour hours=time_of_day.hour - expected_reschedule_time.hour
@ -422,7 +430,7 @@ class TestJobQueue:
calendar.monthrange(now.year, now.month)[1] calendar.monthrange(now.year, now.month)[1]
) - dtm.timedelta(days=now.day) ) - dtm.timedelta(days=now.day)
# Adjust the hour for the special case that between now & end of month a DST switch happens # Adjust the hour for the special case that between now & end of month a DST switch happens
expected_reschedule_time = timezone.normalize(expected_reschedule_time) expected_reschedule_time = self.normalize(expected_reschedule_time, timezone)
expected_reschedule_time += dtm.timedelta( expected_reschedule_time += dtm.timedelta(
hours=time_of_day.hour - expected_reschedule_time.hour hours=time_of_day.hour - expected_reschedule_time.hour
) )