From 656d83562fb0691a9b0e079eabb988010c6031db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Wed, 4 Jun 2025 15:31:27 +0200 Subject: [PATCH 1/9] Fix test with Django 5 when pytz is available --- tests/test_fields.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index d574b07ebc..9f69a26a92 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -16,6 +16,7 @@ except ImportError: pytz = None +import django from django.core.exceptions import ValidationError as DjangoValidationError from django.db.models import IntegerChoices, TextChoices from django.http import QueryDict @@ -1624,7 +1625,8 @@ def test_should_render_date_time_in_default_timezone(self): assert rendered_date == rendered_date_in_timezone -@pytest.mark.skipif(pytz is None, reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.") +@pytest.mark.skipif(pytz is None or django.VERSION >= (5,), + reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.") class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues): """ Invalid values for `DateTimeField` with datetime in DST shift (non-existing or ambiguous) and timezone with DST. From 4e42975bbac0555cdb4dc37563e88ea15ab01996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Wed, 4 Jun 2025 15:38:05 +0200 Subject: [PATCH 2/9] fix formatting --- tests/test_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index 9f69a26a92..e6e9d17ad6 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1626,7 +1626,7 @@ def test_should_render_date_time_in_default_timezone(self): @pytest.mark.skipif(pytz is None or django.VERSION >= (5,), - reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.") + reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.") class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues): """ Invalid values for `DateTimeField` with datetime in DST shift (non-existing or ambiguous) and timezone with DST. From 5b253461c84c251abe6ef7528899d41b73115098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Thu, 5 Jun 2025 08:26:39 +0200 Subject: [PATCH 3/9] remove original condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ülgen Sarıkavak --- tests/test_fields.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index e6e9d17ad6..fdd74dd972 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1625,8 +1625,10 @@ def test_should_render_date_time_in_default_timezone(self): assert rendered_date == rendered_date_in_timezone -@pytest.mark.skipif(pytz is None or django.VERSION >= (5,), - reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.") +@pytest.mark.skipif( + condition=django.VERSION >= (5,), + reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.", +) class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues): """ Invalid values for `DateTimeField` with datetime in DST shift (non-existing or ambiguous) and timezone with DST. From 3817fb928227989235673f80d3aa87d5f0d1943f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Thu, 5 Jun 2025 08:28:50 +0200 Subject: [PATCH 4/9] remove trailing whitespace --- tests/test_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index fdd74dd972..bfa4f24d45 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1626,7 +1626,7 @@ def test_should_render_date_time_in_default_timezone(self): @pytest.mark.skipif( - condition=django.VERSION >= (5,), + condition=django.VERSION >= (5,), reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.", ) class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues): From d3ff351d37560cc63c4fb82b53e54b6224d5969a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Thu, 5 Jun 2025 11:12:50 +0200 Subject: [PATCH 5/9] further improvements --- tests/test_fields.py | 1 + tox.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/test_fields.py b/tests/test_fields.py index bfa4f24d45..bd20ba64d7 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1625,6 +1625,7 @@ def test_should_render_date_time_in_default_timezone(self): assert rendered_date == rendered_date_in_timezone +@pytest.mark.skipif(condition=pytz is None, reason="pytz is not available.") @pytest.mark.skipif( condition=django.VERSION >= (5,), reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.", diff --git a/tox.ini b/tox.ini index 0adcee3a46..e9d8f9e372 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,7 @@ setenv = PYTHONWARNINGS=once deps = django42: Django>=4.2,<5.0 + django42: pytz django50: Django>=5.0,<5.1 django51: Django>=5.1,<5.2 django52: Django>=5.2,<6.0 From a0fbdbd30e2b1d4e2adfbfbf283925d95f3e34f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Thu, 5 Jun 2025 12:52:37 +0200 Subject: [PATCH 6/9] let's not skip the pytz test - it should always be executed when testing against Django 4 --- requirements/requirements-testing.txt | 1 + tests/test_fields.py | 1 - tox.ini | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index 2b39316a00..b435c0f600 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -5,3 +5,4 @@ pytest-django>=4.5.2,<5.0 importlib-metadata<5.0 # temporary pin of attrs attrs==22.1.0 +pytz diff --git a/tests/test_fields.py b/tests/test_fields.py index bd20ba64d7..bfa4f24d45 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1625,7 +1625,6 @@ def test_should_render_date_time_in_default_timezone(self): assert rendered_date == rendered_date_in_timezone -@pytest.mark.skipif(condition=pytz is None, reason="pytz is not available.") @pytest.mark.skipif( condition=django.VERSION >= (5,), reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.", diff --git a/tox.ini b/tox.ini index e9d8f9e372..0adcee3a46 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,6 @@ setenv = PYTHONWARNINGS=once deps = django42: Django>=4.2,<5.0 - django42: pytz django50: Django>=5.0,<5.1 django51: Django>=5.1,<5.2 django52: Django>=5.2,<6.0 From a415b604e992908cb2bd9af3846e9199c983d4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Mon, 21 Jul 2025 13:57:18 +0200 Subject: [PATCH 7/9] add comment to test requirements Co-authored-by: Bruno Alla --- requirements/requirements-testing.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index b435c0f600..b1e3c82eca 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -5,4 +5,4 @@ pytest-django>=4.5.2,<5.0 importlib-metadata<5.0 # temporary pin of attrs attrs==22.1.0 -pytz +pytz # Remove when dropping support for Django<5.0 From ecccc156ed1750ee1fe3ec6b0af70a7ba76b8d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Mon, 21 Jul 2025 14:13:31 +0200 Subject: [PATCH 8/9] simplify the pytz import as it should always be available --- tests/test_fields.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index bfa4f24d45..e09fb4694b 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -10,11 +10,7 @@ from zoneinfo import ZoneInfo import pytest - -try: - import pytz -except ImportError: - pytz = None +import pytz import django from django.core.exceptions import ValidationError as DjangoValidationError @@ -1642,16 +1638,15 @@ class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues): } outputs = {} - if pytz: - class MockTimezone(pytz.BaseTzInfo): - @staticmethod - def localize(value, is_dst): - raise pytz.InvalidTimeError() + class MockTimezone(pytz.BaseTzInfo): + @staticmethod + def localize(value, is_dst): + raise pytz.InvalidTimeError() - def __str__(self): - return 'America/New_York' + def __str__(self): + return 'America/New_York' - field = serializers.DateTimeField(default_timezone=MockTimezone()) + field = serializers.DateTimeField(default_timezone=MockTimezone()) @patch('rest_framework.utils.timezone.datetime_ambiguous', return_value=True) From 89e1ba398f8ee614cb086b75025fc5b81b7783bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Mon, 21 Jul 2025 14:17:06 +0200 Subject: [PATCH 9/9] make isort happy --- tests/test_fields.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index e09fb4694b..56693ed7a2 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -9,10 +9,9 @@ from unittest.mock import patch from zoneinfo import ZoneInfo +import django import pytest import pytz - -import django from django.core.exceptions import ValidationError as DjangoValidationError from django.db.models import IntegerChoices, TextChoices from django.http import QueryDict pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy