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

Restrict timezone names for tests #775

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ New features:

Bug fixes:

- ...
- Restrict timezones tested, see `Issue 763 <https://github.com/collective/icalendar/issues/763>`_

6.1.1 (2025-01-18)
------------------
Expand Down
14 changes: 13 additions & 1 deletion src/icalendar/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
try:
from backports import zoneinfo
from backports import zoneinfo # type: ignore # noqa: PGH003
except ImportError:
import zoneinfo
from typing import Generator

import pytest

import icalendar

from . import timezone_ids

try:
import pytz
except ImportError:
Expand Down Expand Up @@ -337,3 +340,12 @@ def env_for_doctest(monkeypatch):

monkeypatch.setattr(ZONEINFO, "utc", zoneinfo.ZoneInfo("UTC"))
return {"print": doctest_print}


@pytest.fixture(params=timezone_ids.TZIDS)
def tzid(request:pytest.FixtureRequest) -> str:
"""Return a timezone id to be used with pytz or zoneinfo.

This goes through all the different timezones possible.
"""
return request.param
32 changes: 15 additions & 17 deletions src/icalendar/tests/test_timezone_identification.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
"""Test that we can identify all timezones."""
"""Test that we can identify all timezones.

import pytest
try:
from zoneinfo import ZoneInfo, available_timezones
except ImportError:
from backports.zoneinfo import ZoneInfo, available_timezones
Timezones can be removed from ./timezone_ids.py if they make the tests fail:
Timezone information changes over time and can be dependent on the operating system's
timezone database (zoneinfo, dateutil) or the package (pytz).
We want to make sure we can roughly identify most of them.
"""

from icalendar.timezone import tzids_from_tzinfo, tzid_from_tzinfo
from icalendar.timezone import tzid_from_tzinfo, tzids_from_tzinfo
from icalendar.timezone.tzp import TZP

tzids = available_timezones() - {"Factory", "localtime"}
with_tzid = pytest.mark.parametrize("tzid", tzids)

@with_tzid
def test_can_identify_zoneinfo(tzid, zoneinfo_only):
def test_can_identify_zoneinfo(tzid, zoneinfo_only, tzp:TZP):
"""Check that all those zoneinfo timezones can be identified."""
assert tzid in tzids_from_tzinfo(ZoneInfo(tzid))
assert tzid in tzids_from_tzinfo(tzp.timezone(tzid))

@with_tzid
def test_can_identify_pytz(tzid, pytz_only):

def test_can_identify_pytz(tzid, pytz_only, tzp:TZP):
"""Check that all those pytz timezones can be identified."""
import pytz
assert tzid in tzids_from_tzinfo(pytz.timezone(tzid))
assert tzid in tzids_from_tzinfo(tzp.timezone(tzid))


@with_tzid
def test_can_identify_dateutil(tzid):
"""Check that all those dateutil timezones can be identified."""
from dateutil.tz import gettz
assert tzid in tzids_from_tzinfo(gettz(tzid))


def test_utc_is_identified(utc):
"""Test UTC because it is handled in a special way."""
assert "UTC" in tzids_from_tzinfo(utc)
Expand Down
Loading
Loading