From: Aarni Koskela Date: Thu, 16 Apr 2026 12:37:05 +0000 (+0300) Subject: Update tests and code for CLDR 48.2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=f42ed4e9de43ac4f191bee85678abe402aa7937d;p=thirdparty%2Fbabel.git Update tests and code for CLDR 48.2 - Unit IDs renamed in 48 still work (with deprecation warnings raised) --- diff --git a/babel/core.py b/babel/core.py index eb07a8d2..3ba8b85e 100644 --- a/babel/core.py +++ b/babel/core.py @@ -1372,7 +1372,7 @@ def get_cldr_version() -> str: function is a string representing a version number, e.g. '47'. >>> get_cldr_version() - '47' + '48' .. versionadded:: 2.18 diff --git a/babel/numbers.py b/babel/numbers.py index 767bac95..b782521e 100644 --- a/babel/numbers.py +++ b/babel/numbers.py @@ -741,7 +741,7 @@ def format_currency( >>> format_currency(1099.98, 'JPY', locale='en_US') '\\xa51,100' >>> format_currency(1099.98, 'COP', '#,##0.00', locale='es_ES') - '1.099,98' + '1.100' However, the number of decimal digits can be overridden from the currency information, by setting the last parameter to ``False``: diff --git a/babel/units.py b/babel/units.py index 2c346242..fa41260a 100644 --- a/babel/units.py +++ b/babel/units.py @@ -1,11 +1,22 @@ from __future__ import annotations import decimal +import warnings from typing import Literal from babel.core import Locale from babel.numbers import LC_NUMERIC, format_decimal +_DEPRECATED_UNIT_IDS: dict[str, str] = { + # Unit IDs deprecated in CLDR 48 + "concentr-permillion": "concentr-part-per-1e6", + "concentr-portion": "concentr-part", + "concentr-portion-per-1e9": "concentr-part-per-1e9", + "permillion": "part-per-1e6", + "portion": "part", + "portion-per-1e9": "part-per-1e9", +} + class UnknownUnitError(ValueError): def __init__(self, unit: str, locale: Locale) -> None: @@ -66,6 +77,19 @@ def _find_unit_pattern(unit_id: str, locale: Locale | str | None = None) -> str unit_patterns: dict[str, str] = locale._data["unit_patterns"] if unit_id in unit_patterns: return unit_id + + # Only if a direct hit didn't work, try deprecated units... + new_id = _DEPRECATED_UNIT_IDS.get(unit_id) + if new_id is not None: + warnings.warn( + f"Unit identifier {unit_id!r} is deprecated; use {new_id!r} instead.", + DeprecationWarning, + stacklevel=4, + ) + if new_id in unit_patterns: + return new_id + + # ... and finally fuzzy matching. for unit_pattern in sorted(unit_patterns, key=len): if unit_pattern.endswith(unit_id): return unit_pattern diff --git a/tests/test_core.py b/tests/test_core.py index 461d7078..7cb9cd90 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -413,4 +413,4 @@ def test_locale_parse_empty(): def test_get_cldr_version(): - assert core.get_cldr_version() == "47" + assert core.get_cldr_version() == "48" diff --git a/tests/test_dates.py b/tests/test_dates.py index 12bb2343..f80bb328 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -613,10 +613,10 @@ def test_format_time(timezone_getter): def test_format_skeleton(timezone_getter): dt = datetime(2007, 4, 1, 15, 30) assert (dates.format_skeleton('yMEd', dt, locale='en_US') == 'Sun, 4/1/2007') - assert (dates.format_skeleton('yMEd', dt, locale='th') == 'อา. 1/4/2007') + assert (dates.format_skeleton('yMEd', dt, locale='th') == 'อาทิตย์ 1/4/2007') assert (dates.format_skeleton('EHm', dt, locale='en') == 'Sun 15:30') - assert (dates.format_skeleton('EHm', dt, tzinfo=timezone_getter('Asia/Bangkok'), locale='th') == 'อา. 22:30 น.') + assert (dates.format_skeleton('EHm', dt, tzinfo=timezone_getter('Asia/Bangkok'), locale='th') == 'อาทิตย์ 22:30 น.') @pytest.mark.parametrize(('skeleton', 'expected'), [ @@ -1194,8 +1194,8 @@ def test_issue_1192(): # The actual returned value here is not actually strictly specified ("get_timezone_name" # is not an operation specified as such). Issue #1192 concerned this invocation returning # the invalid "no inheritance marker" value; _that_ should never be returned here. - # IOW, if the below "Hawaii-Aleutian Time" changes with e.g. CLDR updates, that's fine. - assert dates.get_timezone_name('Pacific/Honolulu', 'short', locale='en_GB') == "Hawaii-Aleutian Time" + # IOW, if the below "United States (Honolulu) Time" changes with e.g. CLDR updates, that's fine. + assert dates.get_timezone_name('Pacific/Honolulu', 'short', locale='en_GB') == "United States (Honolulu) Time" @pytest.mark.xfail diff --git a/tests/test_lists.py b/tests/test_lists.py index ef522f22..da96a124 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -9,7 +9,7 @@ from babel import lists, units (['string1', 'string2'], 'en', 'string1 and string2'), (['string1', 'string2', 'string3'], 'en', 'string1, string2, and string3'), (['string1', 'string2', 'string3'], 'zh', 'string1、string2和string3'), - (['string1', 'string2', 'string3', 'string4'], 'ne', 'string1,string2, string3 र string4'), + (['string1', 'string2', 'string3', 'string4'], 'ne', 'string1, string2, string3 र string4'), ]) def test_format_list(list, locale, expected): assert lists.format_list(list, locale=locale) == expected diff --git a/tests/test_numbers.py b/tests/test_numbers.py index 4f24f5b8..cf888b7e 100644 --- a/tests/test_numbers.py +++ b/tests/test_numbers.py @@ -40,7 +40,7 @@ def test_list_currencies(): assert list_currencies(locale='pa_Arab') == {'PKR', 'INR', 'EUR'} - assert len(list_currencies()) == 307 + assert len(list_currencies()) == 308 def test_validate_currency(): @@ -297,7 +297,7 @@ def test_format_currency_format_type(): assert (numbers.format_currency(1099.98, 'JPY', locale='en_US') == '\xa51,100') assert (numbers.format_currency(1099.98, 'COP', '#,##0.00', locale='es_ES') - == '1.099,98') + == '1.100') assert (numbers.format_currency(1099.98, 'JPY', locale='en_US', currency_digits=False) == '\xa51,099.98') @@ -320,7 +320,7 @@ def test_format_compact_currency(): assert numbers.format_compact_currency(123, 'EUR', locale='yav', format_type="short") == '€\xa0123' assert numbers.format_compact_currency(12345, 'EUR', locale='yav', format_type="short") == '€\xa012K' assert numbers.format_compact_currency(123456789, 'EUR', locale='de_DE', fraction_digits=1) == '123,5\xa0Mio.\xa0€' - assert numbers.format_compact_currency(123456789, 'USD', locale='ar_EG', fraction_digits=2, format_type="short", numbering_system="default") == '123٫46\xa0مليون\xa0US$' + assert numbers.format_compact_currency(123456789, 'USD', locale='ar_EG', fraction_digits=2, format_type="short", numbering_system="default") == '\u200f123٫46\xa0مليون\xa0US$' def test_format_compact_currency_invalid_format_type(): diff --git a/tests/test_support_format.py b/tests/test_support_format.py index fdfac844..cd9765b1 100644 --- a/tests/test_support_format.py +++ b/tests/test_support_format.py @@ -53,7 +53,7 @@ def test_format_currency(ar_eg_format, en_us_format): def test_format_compact_currency(ar_eg_format, en_us_format): assert en_us_format.compact_currency(1099.98, 'USD') == '$1K' assert en_us_format.compact_currency(Decimal("1099.98"), 'USD') == '$1K' - assert ar_eg_format.compact_currency(1099.98, 'EGP') == '1\xa0ألف\xa0ج.م.\u200f' + assert ar_eg_format.compact_currency(1099.98, 'EGP') == '\u200f1\xa0ألف\xa0ج.م.\u200f' def test_format_percent(ar_eg_format, en_us_format): diff --git a/tests/test_units.py b/tests/test_units.py index 27b7535f..cab9c0a1 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -8,9 +8,9 @@ from babel.units import format_unit ('speed-light-speed', 1, '1 světlo'), ('speed-light-speed', 2, '2 světla'), ('speed-light-speed', 5, '5 světel'), - ('concentr-portion-per-1e9', 1, '1 částice na miliardu'), - ('concentr-portion-per-1e9', 2, '2 částice na miliardu'), - ('concentr-portion-per-1e9', 5, '5 částic na miliardu'), + ('concentr-part-per-1e9', 1, '1 částice na miliardu'), + ('concentr-part-per-1e9', 2, '2 částice na miliardu'), + ('concentr-part-per-1e9', 5, '5 částic na miliardu'), ('duration-night', 1, '1 noc'), ('duration-night', 2, '2 noci'), ('duration-night', 5, '5 nocí'), @@ -29,3 +29,9 @@ def test_new_cldr46_units(unit, count, expected): ]) def test_issue_1217(count, unit, locale, length, expected): assert format_unit(count, unit, length, locale=locale) == expected + + +def test_deprecated_unit_ids(): + for id in ("concentr-permillion", "concentr-portion", "concentr-portion-per-1e9"): + with pytest.warns(DeprecationWarning, match=id): + format_unit(1, id, locale='en')