Open mweinelt opened 1 year ago
Yep, tests are known to do weird things in non-UTC time: #757 #935
Thanks for the additional data point though – and PRs are welcome :)
We are running in UTC time and exporting TZ=UTC
does not work around that issue.
The two doctest tests were fixed by providing pytz
to the test environment. So I've updated the original post.
I've submitted #998 as a partial solution. It freezes the date to get predictable format strings.
That said, I've no clue how to do the same for doctests.
Interestingly, the doctests only fail for me without pytz.
Interestingly, the doctests only fail for me without pytz.
Ah, maybe that's why I couldn't reproduce it at first — I (wrongly) guessed that we aren't running doctests at all on Gentoo. So perhaps fixing just the main suite will be good enough.
With #998, tests pass when pytz
is installed, but there are still two tests failures when pytz
is not installed:
=================================== FAILURES ===================================
______________________ [doctest] babel.dates.format_time _______________________
767
768 These timezone calculations are **not** performed if the value is of type
769 ``datetime.time``, as without date information there's no way to determine
770 what a given time would translate to in a different timezone without
771 information about whether daylight savings time is in effect or not. This
772 means that time values are left as-is, and the value of the `tzinfo`
773 parameter is only used to display the timezone name if needed:
774
775 >>> t = time(15, 30)
776 >>> format_time(t, format='full', tzinfo=get_timezone('Europe/Paris'),
Expected:
u'15:30:00 heure normale d\u2019Europe centrale'
Got:
'15:30:00 heure d’été d’Europe centrale'
/builddir/python3-Babel-2.12.1/babel/dates.py:776: DocTestFailure
___________________ [doctest] babel.dates.get_timezone_name ____________________
536 Return the localized display name for the given timezone. The timezone
537 may be specified using a ``datetime`` or `tzinfo` object.
538
539 >>> from datetime import time
540 >>> dt = time(15, 30, tzinfo=get_timezone('America/Los_Angeles'))
541 >>> get_timezone_name(dt, locale='en_US')
Expected:
u'Pacific Standard Time'
Got:
'Pacific Daylight Time'
/builddir/python3-Babel-2.12.1/babel/dates.py:541: DocTestFailure
The second one has an easy fix, change time(15, 30, ...)
for datetime(2023, 1, 1, 15, 30, ...)
, but I'm not sure about the first one.
But just changing the date here (as done in #998) seems just hiding that there is a discrepancy for timezones with pytz vs zoneinfo:
pytz
is not installed:
$ python
Python 3.11.3 (main, Apr 6 2023, 22:56:38) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import time
>>> from babel.dates import get_timezone, get_timezone_name
>>> dt = time(15, 30, tzinfo=get_timezone('America/Los_Angeles'))
>>> get_timezone_name(dt, locale='en_US')
'Pacific Daylight Time'
>>>
pytz
is installed:
$ python
Python 3.11.3 (main, Apr 6 2023, 22:56:38) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import time
>>> from babel.dates import get_timezone, get_timezone_name
>>> dt = time(15, 30, tzinfo=get_timezone('America/Los_Angeles'))
>>> get_timezone_name(dt, locale='en_US')
'Pacific Standard Time'
Which one is the correct behaviour?
Overview Description
Timezone related test fails on Babel 1.12.1 around when eastern daylight and eastern standard time swap.
Steps to Reproduce
Actual Results
Expected Results
Tests should likely be frozen in time.
Reproducibility
Around when the daylight saving time goes in and out of effect.
Additional Information