From 6cf5e1c3587f776c9583d14dfbf6efc8bb546fea Mon Sep 17 00:00:00 2001 From: Jeff <138259519+jdotc1@users.noreply.github.com> Date: Tue, 27 Oct 2026 01:55:39 -0400 Subject: [PATCH 1/2] Resolve deprecated short unit identifiers through their replacements --- babel/units.py | 1 + tests/test_units.py | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/babel/units.py b/babel/units.py index 0f32014aa..52fc56a41 100644 --- a/babel/units.py +++ b/babel/units.py @@ -88,6 +88,7 @@ def _find_unit_pattern(unit_id: str, locale: Locale | str | None = None) -> str ) if new_id in unit_patterns: return new_id + unit_id = new_id # ... and finally fuzzy matching. for unit_pattern in sorted(unit_patterns, key=len): diff --git a/tests/test_units.py b/tests/test_units.py index dcb938775..8cb230836 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -37,10 +37,27 @@ 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') +@pytest.mark.parametrize( + ('unit_id', 'replacement'), + [ + ('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'), + ], +) +def test_deprecated_unit_ids(unit_id, replacement): + with pytest.warns(DeprecationWarning, match=unit_id) as warnings: + formatted = format_unit(1, unit_id, locale='en') + assert len(warnings) == 1 + assert formatted == format_unit(1, replacement, locale='en') + + with pytest.warns(DeprecationWarning, match=unit_id) as warnings: + name = get_unit_name(unit_id, locale='en') + assert len(warnings) == 1 + assert name == get_unit_name(replacement, locale='en') @pytest.mark.parametrize( From 12392bb6edd07cb6cb4de5e7f370e64b3438126e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 30 Oct 2026 13:18:05 +0200 Subject: [PATCH 2/2] Simplify tests --- tests/test_units.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/tests/test_units.py b/tests/test_units.py index 8cb230836..9a6fd6035 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -1,6 +1,8 @@ +from functools import partial + import pytest -from babel.units import format_unit, get_unit_name +from babel.units import _DEPRECATED_UNIT_IDS, format_unit, get_unit_name # New units in CLDR 46 @@ -37,27 +39,13 @@ def test_issue_1217(count, unit, locale, length, expected): assert format_unit(count, unit, length, locale=locale) == expected -@pytest.mark.parametrize( - ('unit_id', 'replacement'), - [ - ('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'), - ], -) +@pytest.mark.parametrize(('unit_id', 'replacement'), _DEPRECATED_UNIT_IDS.items()) def test_deprecated_unit_ids(unit_id, replacement): - with pytest.warns(DeprecationWarning, match=unit_id) as warnings: - formatted = format_unit(1, unit_id, locale='en') - assert len(warnings) == 1 - assert formatted == format_unit(1, replacement, locale='en') - - with pytest.warns(DeprecationWarning, match=unit_id) as warnings: - name = get_unit_name(unit_id, locale='en') - assert len(warnings) == 1 - assert name == get_unit_name(replacement, locale='en') + for func in (partial(format_unit, 1), get_unit_name): + with pytest.warns(DeprecationWarning, match=unit_id) as record: + result = func(unit_id, locale='en') + assert len(record) == 1 + assert result == func(replacement, locale='en') @pytest.mark.parametrize(