Skip to content

Commit

Permalink
Merge pull request #775 from niccokunzmann/issue-763
Browse files Browse the repository at this point in the history
Restrict timezone names for tests
  • Loading branch information
niccokunzmann authored Feb 20, 2025
2 parents a169c11 + 10bd46d commit 4ffa5cd
Show file tree
Hide file tree
Showing 6 changed files with 1,123 additions and 468 deletions.
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

0 comments on commit 4ffa5cd

Please sign in to comment.