Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pytz dependency in tests #3165

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release type: patch

External dependency `pytz` has already been removed from the main code, but this PR also
removes it from the tests.
1 change: 0 additions & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ automatically installed without any action on your part:
* `pygments <https://pypi.org/project/Pygments/>`_, for syntax highlighting
* `docutils <https://pypi.org/project/docutils/>`_, for supporting
reStructuredText as an input format
* `pytz <https://pypi.org/project/pytz/>`_, for timezone definitions
* `blinker <https://pypi.org/project/blinker/>`_, an object-to-object and
broadcast signaling system
* `unidecode <https://pypi.org/project/Unidecode/>`_, for ASCII
Expand Down
6 changes: 3 additions & 3 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from urllib.parse import unquote, urljoin, urlparse, urlunparse

try:
import zoneinfo
from zoneinfo import ZoneInfo
except ModuleNotFoundError:
from backports import zoneinfo
from backports.zoneinfo import ZoneInfo


from pelican.plugins import signals
Expand Down Expand Up @@ -127,7 +127,7 @@ def __init__(self, content, metadata=None, settings=None,
# manage timezone
default_timezone = settings.get("TIMEZONE", "UTC")
timezone = getattr(self, "timezone", default_timezone)
self.timezone = zoneinfo.ZoneInfo(timezone)
self.timezone = ZoneInfo(timezone)

if hasattr(self, 'date'):
self.date = set_date_tzinfo(self.date, timezone)
Expand Down
22 changes: 13 additions & 9 deletions pelican/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import os
import shutil
import time
from datetime import timezone
from sys import platform
from tempfile import mkdtemp

import pytz
try:
from zoneinfo import ZoneInfo
except ModuleNotFoundError:
from backports.zoneinfo import ZoneInfo

from pelican import utils
from pelican.generators import TemplatePagesGenerator
Expand Down Expand Up @@ -50,21 +54,21 @@ def test_get_date(self):
year=2012, month=11, day=22, hour=22, minute=11)
date_hour_z = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11,
tzinfo=pytz.timezone('UTC'))
tzinfo=timezone.utc)
date_hour_est = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11,
tzinfo=pytz.timezone('EST'))
tzinfo=ZoneInfo("EST"))
date_hour_sec = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11, second=10)
date_hour_sec_z = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11, second=10,
tzinfo=pytz.timezone('UTC'))
tzinfo=timezone.utc)
date_hour_sec_est = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11, second=10,
tzinfo=pytz.timezone('EST'))
tzinfo=ZoneInfo("EST"))
date_hour_sec_frac_z = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11, second=10,
microsecond=123000, tzinfo=pytz.timezone('UTC'))
microsecond=123000, tzinfo=timezone.utc)
dates = {
'2012-11-22': date,
'2012/11/22': date,
Expand All @@ -86,13 +90,13 @@ def test_get_date(self):
iso_8601_date = utils.SafeDatetime(year=1997, month=7, day=16)
iso_8601_date_hour_tz = utils.SafeDatetime(
year=1997, month=7, day=16, hour=19, minute=20,
tzinfo=pytz.timezone('CET'))
tzinfo=ZoneInfo("Europe/London"))
iso_8601_date_hour_sec_tz = utils.SafeDatetime(
year=1997, month=7, day=16, hour=19, minute=20, second=30,
tzinfo=pytz.timezone('CET'))
tzinfo=ZoneInfo("Europe/London"))
iso_8601_date_hour_sec_ms_tz = utils.SafeDatetime(
year=1997, month=7, day=16, hour=19, minute=20, second=30,
microsecond=450000, tzinfo=pytz.timezone('CET'))
microsecond=450000, tzinfo=ZoneInfo("Europe/London"))
iso_8601 = {
'1997-07-16': iso_8601_date,
'1997-07-16T19:20+01:00': iso_8601_date_hour_tz,
Expand Down
6 changes: 3 additions & 3 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import dateutil.parser

try:
import zoneinfo
from zoneinfo import ZoneInfo
except ModuleNotFoundError:
from backports import zoneinfo
from backports.zoneinfo import ZoneInfo
from markupsafe import Markup


Expand Down Expand Up @@ -921,7 +921,7 @@ def file_watcher(path):
def set_date_tzinfo(d, tz_name=None):
"""Set the timezone for dates that don't have tzinfo"""
if tz_name and not d.tzinfo:
timezone = zoneinfo.ZoneInfo(tz_name)
timezone = ZoneInfo(tz_name)
d = d.replace(tzinfo=timezone)
return SafeDatetime(
d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond, d.tzinfo
Expand Down