Skip to content

Commit

Permalink
use zoneinfo instead of pytz
Browse files Browse the repository at this point in the history
  • Loading branch information
saranti committed Jul 7, 2024
1 parent 41717e5 commit d3fe586
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ test = [
"pytest",
"pytest-cov",
"pytest-mock",
"pytz==2021.1",
"simplejson==3.*",
]
doc = [
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ pre-commit
pytest
pytest-cov
pytest-mock
pytz==2021.1
simplejson==3.*
5 changes: 2 additions & 3 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit d3fe586

Please sign in to comment.