Skip to content
Open
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
25 changes: 21 additions & 4 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down