Fix DST-related test failures

This commit is contained in:
Miro Hrončok 2023-04-10 10:54:41 +02:00
parent d30687f37d
commit 1fe2203f3d
2 changed files with 51 additions and 1 deletions

43
998.patch Normal file
View File

@ -0,0 +1,43 @@
From 641f58c9951d9f5746cd63743dd337f1340d7bff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Fri, 7 Apr 2023 14:51:10 +0000
Subject: [PATCH] Freeze format_time() tests to a specific date to fix test
failures
Freeze the date when performing the tests for format_time() with
a timezone specified. Since the time object does not specify a date,
the formatter uses the format string specific to the current date.
As a result, if the current DST state is different than when the test
was last updated, it failed.
This fix covers only regular tests. I have no idea how to do the same
for doctests.
Issue #988
---
tests/test_dates.py | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/tests/test_dates.py b/tests/test_dates.py
index b94c710f..3f1fc3fc 100644
--- a/tests/test_dates.py
+++ b/tests/test_dates.py
@@ -601,12 +601,13 @@ def test_format_time(timezone_getter):
custom = dates.format_time(t, "hh 'o''clock' a, zzzz", tzinfo=eastern, locale='en')
assert custom == "09 o'clock AM, Eastern Daylight Time"
- t = time(15, 30)
- paris = dates.format_time(t, format='full', tzinfo=paris, locale='fr_FR')
- assert paris == '15:30:00 heure normale dEurope centrale'
+ with freezegun.freeze_time("2023-01-01"):
+ t = time(15, 30)
+ paris = dates.format_time(t, format='full', tzinfo=paris, locale='fr_FR')
+ assert paris == '15:30:00 heure normale dEurope centrale'
- us_east = dates.format_time(t, format='full', tzinfo=eastern, locale='en_US')
- assert us_east == '3:30:00\u202fPM Eastern Standard Time'
+ us_east = dates.format_time(t, format='full', tzinfo=eastern, locale='en_US')
+ assert us_east == '3:30:00\u202fPM Eastern Standard Time'
def test_format_skeleton(timezone_getter):

View File

@ -15,13 +15,17 @@
Name: babel
Version: 2.12.1
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Tools for internationalizing Python applications
License: BSD-3-Clause
URL: https://babel.pocoo.org/
Source: %{pypi_source Babel}
# Freeze format_time() tests to a specific date to fix test failures
# Fixes https://bugzilla.redhat.com/2179515
Patch: https://github.com/python-babel/babel/pull/998.patch
BuildArch: noarch
BuildRequires: python3-devel
@ -129,6 +133,9 @@ export TZ=UTC
%endif
%changelog
* Mon Apr 10 2023 Miro Hrončok <mhroncok@redhat.com> - 2.12.1-2
- Fix DST-related test failures
* Wed Mar 01 2023 Miro Hrončok <mhroncok@redhat.com> - 2.12.1-1
- Update to 2.12.1