From ad4d460591ec67d8d684897546ca067b1087b95a Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:17:51 +0100 Subject: [PATCH] try fixing jobqueue tests --- tests/ext/test_jobqueue.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/ext/test_jobqueue.py b/tests/ext/test_jobqueue.py index 5aa57d611..aa737442e 100644 --- a/tests/ext/test_jobqueue.py +++ b/tests/ext/test_jobqueue.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. import asyncio import calendar +import contextlib import datetime as dtm import logging import platform @@ -77,6 +78,13 @@ class TestJobQueue: job_time = 0 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): jq = JobQueue() jq.set_application(app) @@ -400,7 +408,7 @@ class TestJobQueue: if day > 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 expected_reschedule_time += dtm.timedelta( hours=time_of_day.hour - expected_reschedule_time.hour @@ -422,7 +430,7 @@ class TestJobQueue: calendar.monthrange(now.year, now.month)[1] ) - dtm.timedelta(days=now.day) # 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( hours=time_of_day.hour - expected_reschedule_time.hour )