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
7 changes: 6 additions & 1 deletion babel/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ def format_compound_unit(

# Look for a specific compound unit first...

if numerator_unit and denominator_unit and denominator_value == 1:
if (
not isinstance(numerator_value, str)
and numerator_unit
and denominator_unit
and denominator_value == 1
):
compound_unit = _find_compound_unit(numerator_unit, denominator_unit, locale=locale)
if compound_unit:
return format_unit(
Expand Down
14 changes: 13 additions & 1 deletion tests/test_units.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import pytest

from babel.units import format_unit, get_unit_name
from babel.units import format_compound_unit, format_unit, get_unit_name


@pytest.mark.parametrize('locale', ['en', 'fi', 'fr'])
@pytest.mark.parametrize('length', ['long', 'short', 'narrow'])
@pytest.mark.parametrize('value', ['custom label', '1 kg'])
def test_compound_unit_preformatted_numerator_ignores_unit(locale, length, value):
expected = format_compound_unit(
value, denominator_unit='hour', length=length, locale=locale,
)
assert format_compound_unit(
value, 'kilometer', denominator_unit='hour', length=length, locale=locale,
) == expected


# New units in CLDR 46
Expand Down