Patch-Source: https://github.com/pimutils/khal/commit/f6c9b8a53a0f12222b2ee25c82229b0605b8785a From f6c9b8a53a0f12222b2ee25c82229b0605b8785a Mon Sep 17 00:00:00 2001 From: Christian Geier Date: Tue, 30 Aug 2022 23:26:23 +0200 Subject: [PATCH] tests working with latest pytz version We had assumed that pytz versions would always follow the schema year.month, but pytz 2022.2.1 broke that assumption and our code. We should now be able to deal with pytz versions in the year.month.anything. fix #1180 --- CHANGELOG.rst | 2 ++ setup.py | 1 + tests/conftest.py | 8 -------- tests/event_test.py | 5 +++-- tests/vtimezone_test.py | 5 +++-- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d5e436ea7..10bc52bbe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,6 @@ from time import sleep import pytest -import pytz from khal.custom_types import CalendarConfiguration from khal.khalendar import CalendarCollection @@ -144,13 +143,6 @@ def touch_and_mtime(): ) -@pytest.fixture(scope='session') -def pytz_version(): - """Return the version of pytz as a tuple.""" - year, month = pytz.__version__.split('.') - return int(year), int(month) - - @pytest.fixture def fix_caplog(monkeypatch): """Temporarily undoes the logging setup by click-log such that the caplog fixture can be used""" diff --git a/tests/event_test.py b/tests/event_test.py index af74bf9b9..92dc998f8 100644 --- a/tests/event_test.py +++ b/tests/event_test.py @@ -6,6 +6,7 @@ from hypothesis import event, given from hypothesis.strategies import datetimes from icalendar import Parameters, vCalAddress, vRecur, vText +from packaging import version from khal.khalendar.event import (AllDayEvent, Event, FloatingEvent, LocalizedEvent, create_timezone) @@ -341,12 +342,12 @@ def test_event_dt_long(): '09.04.2014 09:30-12.04.2014 10:30 An Event\x1b[0m' -def test_event_no_dst(pytz_version): +def test_event_no_dst(): """test the creation of a corect VTIMEZONE for timezones with no dst""" event_no_dst = _get_text('event_no_dst') cal_no_dst = _get_text('cal_no_dst') event = Event.fromString(event_no_dst, calendar='foobar', locale=LOCALE_BOGOTA) - if pytz_version > (2017, 1): + if version.parse(pytz.__version__) > version.Version('2017.1'): cal_no_dst = cal_no_dst.replace( 'TZNAME:COT', 'RDATE:20380118T221407\r\nTZNAME:-05' diff --git a/tests/vtimezone_test.py b/tests/vtimezone_test.py index d19936cca..0dbe60bd6 100644 --- a/tests/vtimezone_test.py +++ b/tests/vtimezone_test.py @@ -1,6 +1,7 @@ import datetime as dt import pytz +from packaging import version from khal.khalendar.event import create_timezone @@ -63,7 +64,7 @@ def test_berlin_rdate(): assert vberlin_dst in vberlin -def test_bogota(pytz_version): +def test_bogota(): vbogota = [b'BEGIN:VTIMEZONE', b'TZID:America/Bogota', b'BEGIN:STANDARD', @@ -74,7 +75,7 @@ def test_bogota(pytz_version): b'END:STANDARD', b'END:VTIMEZONE', b''] - if pytz_version > (2017, 1): + if version.parse(pytz.__version__) > version.Version('2017.1'): vbogota[4] = b'TZNAME:-05' vbogota.insert(4, b'RDATE:20380118T221407')