Fixed #29578 -- Made numberformat.format() honor forced l10n usage.

Thanks Sassan Haradji for the report.
This commit is contained in:
Claude Paroz 2018-07-19 22:44:40 +02:00 committed by Tim Graham
parent 6b6bdfe25c
commit 0adfba968e
5 changed files with 26 additions and 18 deletions

View file

@ -1,11 +1,11 @@
from decimal import Decimal
from sys import float_info
from unittest import TestCase
from django.test import SimpleTestCase
from django.utils.numberformat import format as nformat
class TestNumberFormat(TestCase):
class TestNumberFormat(SimpleTestCase):
def test_format_number(self):
self.assertEqual(nformat(1234, '.'), '1234')
@ -14,6 +14,11 @@ class TestNumberFormat(TestCase):
self.assertEqual(nformat(1234, '.', grouping=2, thousand_sep=','), '1234')
self.assertEqual(nformat(1234, '.', grouping=2, thousand_sep=',', force_grouping=True), '12,34')
self.assertEqual(nformat(-1234.33, '.', decimal_pos=1), '-1234.3')
# The use_l10n parameter can force thousand grouping behavior.
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True):
self.assertEqual(nformat(1234, '.', grouping=3, thousand_sep=',', use_l10n=False), '1234')
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False):
self.assertEqual(nformat(1234, '.', grouping=3, thousand_sep=',', use_l10n=True), '1,234')
def test_format_string(self):
self.assertEqual(nformat('1234', '.'), '1234')