refactor: pytz -> ZoneInfo
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
ad1ed62652
commit
94fe90de66
2 changed files with 10 additions and 7 deletions
|
|
@ -814,15 +814,19 @@ def get_tests_CompatFrappeTestCase():
|
|||
|
||||
@contextmanager
|
||||
def freeze_time(self, time_to_freeze, is_utc=False, *args, **kwargs):
|
||||
import pytz
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from frappe.utils.data import convert_utc_to_timezone, get_datetime, get_system_timezone
|
||||
|
||||
if not is_utc:
|
||||
# Freeze time expects UTC or tzaware objects. We have neither, so convert to UTC.
|
||||
timezone = pytz.timezone(get_system_timezone())
|
||||
time_to_freeze = timezone.localize(get_datetime(time_to_freeze)).astimezone(pytz.utc)
|
||||
time_to_freeze = (
|
||||
get_datetime(time_to_freeze)
|
||||
.replace(tzinfo=ZoneInfo(get_system_timezone()))
|
||||
.astimezone(ZoneInfo("UTC"))
|
||||
)
|
||||
|
||||
with freeze_time(time_to_freeze, *args, **kwargs):
|
||||
yield
|
||||
|
|
|
|||
|
|
@ -5,14 +5,13 @@ import io
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from datetime import date, datetime, time, timedelta, timezone
|
||||
from decimal import ROUND_HALF_UP, Decimal, localcontext
|
||||
from enum import Enum
|
||||
from io import StringIO
|
||||
from mimetypes import guess_type
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytz
|
||||
from hypothesis import given
|
||||
from hypothesis import strategies as st
|
||||
from PIL import Image
|
||||
|
|
@ -736,9 +735,9 @@ class TestResponse(IntegrationTestCase):
|
|||
minute=23,
|
||||
second=23,
|
||||
microsecond=23,
|
||||
tzinfo=pytz.utc,
|
||||
tzinfo=timezone.utc,
|
||||
),
|
||||
time(hour=23, minute=23, second=23, microsecond=23, tzinfo=pytz.utc),
|
||||
time(hour=23, minute=23, second=23, microsecond=23, tzinfo=timezone.utc),
|
||||
timedelta(days=10, hours=12, minutes=120, seconds=10),
|
||||
],
|
||||
"float": [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue