Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions babel/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 10 additions & 5 deletions tests/test_units.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,10 +39,13 @@ 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'), _DEPRECATED_UNIT_IDS.items())
def test_deprecated_unit_ids(unit_id, replacement):
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(
Expand Down
Loading