Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use the deprecated format_number function internally or in tests #839

Merged
merged 2 commits into from Feb 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions babel/support.py
Expand Up @@ -18,7 +18,7 @@
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
from babel.numbers import format_decimal, format_currency, \
format_percent, format_scientific


Expand Down Expand Up @@ -98,7 +98,7 @@ def number(self, number):
>>> fmt.number(1099)
u'1,099'
"""
return format_number(number, locale=self.locale)
return format_decimal(number, locale=self.locale)

def decimal(self, number, format=None):
"""Return a decimal number formatted for the locale.
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -6,6 +6,9 @@ norecursedirs = venv* .* _* scripts {args}
doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE ALLOW_UNICODE IGNORE_EXCEPTION_DETAIL
markers =
all_locales: parameterize test with all locales
filterwarnings =
# The doctest for format_number would raise this, but we don't really want to see it.
ignore:babel.numbers.format_decimal:DeprecationWarning

[bdist_wheel]
universal = 1
Expand Down
7 changes: 2 additions & 5 deletions tests/test_numbers.py
Expand Up @@ -346,12 +346,9 @@ def test_decimal_precision():
assert get_decimal_precision(decimal.Decimal('10000')) == 0


def test_format_number():
assert numbers.format_number(1099, locale='en_US') == u'1,099'
assert numbers.format_number(1099, locale='de_DE') == u'1.099'


def test_format_decimal():
assert numbers.format_decimal(1099, locale='en_US') == u'1,099'
assert numbers.format_decimal(1099, locale='de_DE') == u'1.099'
assert numbers.format_decimal(1.2345, locale='en_US') == u'1.234'
assert numbers.format_decimal(1.2346, locale='en_US') == u'1.235'
assert numbers.format_decimal(-1.2346, locale='en_US') == u'-1.235'
Expand Down