python-babel / flask-babel

i18n and l10n support for Flask based on Babel and pytz
https://python-babel.github.io/flask-babel/
Other
432 stars 159 forks source link

4.0.0: test suite fails in 4 units with pytest 8.2.1 #239

Open kloczek opened 1 month ago

kloczek commented 1 month ago

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output: ```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-flask-babel-4.0.0-4.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-flask-babel-4.0.0-4.fc37.x86_64/usr/lib/python3.10/site-packages + /usr/bin/pytest -ra -m 'not network' ==================================================================================== test session starts ==================================================================================== platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0 rootdir: /home/tkloczko/rpmbuild/BUILD/flask-babel-4.0.0 configfile: pyproject.toml plugins: time-machine-2.14.1, datadir-1.5.0, regressions-2.5.0, timeout-2.3.1, mock-3.14.0 collected 31 items tests/test_app_factory.py . [ 3%] tests/test_date_formatting.py FFFF [ 16%] tests/test_force_locale.py .... [ 29%] tests/test_gettext.py ............. [ 70%] tests/test_integration.py ....... [ 93%] tests/test_multiple_apps.py . [ 96%] tests/test_number_formatting.py . [100%] ========================================================================================= FAILURES ========================================================================================== ________________________________________________________________________________________ test_basics ________________________________________________________________________________________ def test_basics(): app = flask.Flask(__name__) babel.Babel(app) d = datetime(2010, 4, 12, 13, 46) delta = timedelta(days=6) with app.test_request_context(): assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00\u202fPM' assert babel.format_date(d) == 'Apr 12, 2010' assert babel.format_time(d) == '1:46:00\u202fPM' assert babel.format_timedelta(delta) == '1 week' assert babel.format_timedelta(delta, threshold=1) == '6 days' with app.test_request_context(): get_babel(app).default_timezone = 'Europe/Vienna' > assert babel.format_datetime(d) == 'Apr 12, 2010, 3:46:00\u202fPM' E AssertionError: assert 'Apr 12, 2010...46:00\u202fPM' == 'Apr 12, 2010...46:00\u202fPM' E E - Apr 12, 2010, 3:46:00 PM E ? ^ E + Apr 12, 2010, 1:46:00 PM E ? ^ tests/test_date_formatting.py:24: AssertionError ____________________________________________________________________________________ test_custom_formats ____________________________________________________________________________________ def test_custom_formats(): app = flask.Flask(__name__) app.config.update( BABEL_DEFAULT_LOCALE='en_US', BABEL_DEFAULT_TIMEZONE='Pacific/Johnston' ) b = babel.Babel(app) b.date_formats['datetime'] = 'long' b.date_formats['datetime.long'] = 'MMMM d, yyyy h:mm:ss a' d = datetime(2010, 4, 12, 13, 46) with app.test_request_context(): > assert babel.format_datetime(d) == 'April 12, 2010 3:46:00 AM' E AssertionError: assert 'April 12, 2010 1:46:00 PM' == 'April 12, 2010 3:46:00 AM' E E - April 12, 2010 3:46:00 AM E ? ^ ^ E + April 12, 2010 1:46:00 PM E ? ^ ^ tests/test_date_formatting.py:46: AssertionError ________________________________________________________________________________ test_custom_locale_selector ________________________________________________________________________________ def test_custom_locale_selector(): app = flask.Flask(__name__) b = babel.Babel(app) d = datetime(2010, 4, 12, 13, 46) the_timezone = 'UTC' the_locale = 'en_US' def select_locale(): return the_locale def select_timezone(): return the_timezone get_babel(app).locale_selector = select_locale get_babel(app).timezone_selector = select_timezone with app.test_request_context(): assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00\u202fPM' the_locale = 'de_DE' the_timezone = 'Europe/Vienna' with app.test_request_context(): > assert babel.format_datetime(d) == '12.04.2010, 15:46:00' E AssertionError: assert '12.04.2010, 13:46:00' == '12.04.2010, 15:46:00' E E - 12.04.2010, 15:46:00 E ? ^ E + 12.04.2010, 13:46:00 E ? ^ tests/test_date_formatting.py:73: AssertionError ______________________________________________________________________________________ test_refreshing ______________________________________________________________________________________ def test_refreshing(): app = flask.Flask(__name__) babel.Babel(app) d = datetime(2010, 4, 12, 13, 46) with app.test_request_context(): assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00\u202fPM' get_babel(app).default_timezone = 'Europe/Vienna' babel.refresh() > assert babel.format_datetime(d) == 'Apr 12, 2010, 3:46:00\u202fPM' E AssertionError: assert 'Apr 12, 2010...46:00\u202fPM' == 'Apr 12, 2010...46:00\u202fPM' E E - Apr 12, 2010, 3:46:00 PM E ? ^ E + Apr 12, 2010, 1:46:00 PM E ? ^ tests/test_date_formatting.py:84: AssertionError ================================================================================== short test summary info ================================================================================== FAILED tests/test_date_formatting.py::test_basics - AssertionError: assert 'Apr 12, 2010...46:00\u202fPM' == 'Apr 12, 2010...46:00\u202fPM' FAILED tests/test_date_formatting.py::test_custom_formats - AssertionError: assert 'April 12, 2010 1:46:00 PM' == 'April 12, 2010 3:46:00 AM' FAILED tests/test_date_formatting.py::test_custom_locale_selector - AssertionError: assert '12.04.2010, 13:46:00' == '12.04.2010, 15:46:00' FAILED tests/test_date_formatting.py::test_refreshing - AssertionError: assert 'Apr 12, 2010...46:00\u202fPM' == 'Apr 12, 2010...46:00\u202fPM' =============================================================================== 4 failed, 27 passed in 0.46s ================================================================================ ```
List of installed modules in build env: ```console Package Version ----------------------------- ----------- alabaster 0.7.16 Babel 2.15.0 blinker 1.7.0 build 1.2.1 charset-normalizer 3.3.2 click 8.1.7 defusedxml 0.7.1 docutils 0.20.1 exceptiongroup 1.1.3 fastjsonschema 2.19.1 Flask 3.0.3 idna 3.7 imagesize 1.4.1 importlib_metadata 7.1.0 iniconfig 2.0.0 installer 0.7.0 itsdangerous 2.1.2 Jinja2 3.1.4 lark 1.1.9 MarkupSafe 2.1.5 packaging 24.0 pluggy 1.5.0 poetry-core 1.9.0 Pygments 2.18.0 pyproject_hooks 1.0.0 pytest 8.2.1 pytest-mock 3.14.0 python-dateutil 2.9.0.post0 pytz 2024.1 requests 2.32.2 snowballstemmer 2.2.0 Sphinx 7.3.7 sphinxcontrib-applehelp 1.0.8 sphinxcontrib-devhelp 1.0.6 sphinxcontrib-htmlhelp 2.0.5 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.7 sphinxcontrib-serializinghtml 1.1.10 tokenize_rt 5.2.0 tomli 2.0.1 urllib3 2.2.1 Werkzeug 3.0.3 wheel 0.43.0 zipp 3.19.0 ```

Please let me know if you need more details or want me to perform some diagnostics.

TkTech commented 2 weeks ago

This seems like an issue with pytz rather than flask-babel at first glance. Did you build pytz locally with an invalid tzdata?

kloczek commented 2 weeks ago

I'm using latest tzdata 2024a. pytz is build locally but noting changes code of that module during the pep517 build. BTW use of pytz should be replaced like in RFE example https://github.com/python-babel/flask-babel/issues/240