From d3fe586794ef7ab66aa69b13f347c357f4363d6d Mon Sep 17 00:00:00 2001 From: saranti Date: Sun, 7 Jul 2024 19:09:17 +1000 Subject: [PATCH] use zoneinfo instead of pytz --- pyproject.toml | 1 - requirements/requirements-tests.txt | 1 - tests/test_arrow.py | 5 ++--- tests/test_formatter.py | 8 +++++--- tests/utils.py | 9 ++++++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5ccc497a1..a83455ab9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ test = [ "pytest", "pytest-cov", "pytest-mock", - "pytz==2021.1", "simplejson==3.*", ] doc = [ diff --git a/requirements/requirements-tests.txt b/requirements/requirements-tests.txt index 77005e0b5..a59a88a76 100644 --- a/requirements/requirements-tests.txt +++ b/requirements/requirements-tests.txt @@ -4,5 +4,4 @@ pre-commit pytest pytest-cov pytest-mock -pytz==2021.1 simplejson==3.* diff --git a/tests/test_arrow.py b/tests/test_arrow.py index 507c1ab0f..b899e8903 100644 --- a/tests/test_arrow.py +++ b/tests/test_arrow.py @@ -6,7 +6,6 @@ import dateutil import pytest -import pytz import simplejson as json from dateutil import tz from dateutil.relativedelta import FR, MO, SA, SU, TH, TU, WE @@ -57,9 +56,9 @@ def test_init(self): assert result._datetime == self.expected # regression tests for issue #626 - def test_init_pytz_timezone(self): + def test_init_timezone(self): result = arrow.Arrow( - 2013, 2, 2, 12, 30, 45, 999999, tzinfo=pytz.timezone("Europe/Paris") + 2013, 2, 2, 12, 30, 45, 999999, tzinfo=tz.gettz("Europe/Paris") ) self.expected = datetime( 2013, 2, 2, 12, 30, 45, 999999, tzinfo=tz.gettz("Europe/Paris") diff --git a/tests/test_formatter.py b/tests/test_formatter.py index 0b6c256cf..2385f17b1 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -1,7 +1,9 @@ +try: + import zoneinfo +except ImportError: + from backports import zoneinfo from datetime import datetime - import pytest -import pytz from dateutil import tz as dateutil_tz from arrow import ( @@ -124,7 +126,7 @@ def test_timezone(self): @pytest.mark.parametrize("full_tz_name", make_full_tz_list()) def test_timezone_formatter(self, full_tz_name): # This test will fail if we use "now" as date as soon as we change from/to DST - dt = datetime(1986, 2, 14, tzinfo=pytz.timezone("UTC")).replace( + dt = datetime(1986, 2, 14, tzinfo=zoneinfo.ZoneInfo("UTC")).replace( tzinfo=dateutil_tz.gettz(full_tz_name) ) abbreviation = dt.tzname() diff --git a/tests/utils.py b/tests/utils.py index 95b47c166..7a74b7e46 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,11 +1,14 @@ -import pytz +try: + import zoneinfo +except ImportError: + from backports import zoneinfo from dateutil.zoneinfo import get_zonefile_instance def make_full_tz_list(): dateutil_zones = set(get_zonefile_instance().zones) - pytz_zones = set(pytz.all_timezones) - return dateutil_zones.union(pytz_zones) + zoneinfo_zones = set(zoneinfo.available_timezones()) + return dateutil_zones.union(zoneinfo_zones) def assert_datetime_equality(dt1, dt2, within=10):