summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-02-23 14:37:02 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-26 16:02:53 +0100
commitbc1c03407649a37a8a3c26b8d0cb355ab2fc128e (patch)
tree57044fa8e1f991b6a57395dc2679465d87147d81 /tests/utils_tests
parent667f784baab31f11d2469e5d22bbdc2390dbc030 (diff)
Fixed #28280 -- Prevented numberformat.format() from formatting large/tiny floats in scientific notation.
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_numberformat.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/tests/utils_tests/test_numberformat.py b/tests/utils_tests/test_numberformat.py
index 83e7d271b5..201e2cfe87 100644
--- a/tests/utils_tests/test_numberformat.py
+++ b/tests/utils_tests/test_numberformat.py
@@ -55,10 +55,30 @@ class TestNumberFormat(SimpleTestCase):
self.assertEqual(nformat(-2 * int_max, '.'), most_max2.format('-'))
def test_float_numbers(self):
- # A float without a fractional part (3.) results in a ".0" when no
- # decimal_pos is given. Contrast that with the Decimal('3.') case in
- # test_decimal_numbers which doesn't return a fractional part.
- self.assertEqual(nformat(3., '.'), '3.0')
+ tests = [
+ (9e-10, 10, '0.0000000009'),
+ (9e-19, 2, '0.00'),
+ (.00000000000099, 0, '0'),
+ (.00000000000099, 13, '0.0000000000009'),
+ (1e16, None, '10000000000000000'),
+ (1e16, 2, '10000000000000000.00'),
+ # A float without a fractional part (3.) results in a ".0" when no
+ # decimal_pos is given. Contrast that with the Decimal('3.') case
+ # in test_decimal_numbers which doesn't return a fractional part.
+ (3., None, '3.0'),
+ ]
+ for value, decimal_pos, expected_value in tests:
+ with self.subTest(value=value, decimal_pos=decimal_pos):
+ self.assertEqual(nformat(value, '.', decimal_pos), expected_value)
+ # Thousand grouping behavior.
+ self.assertEqual(
+ nformat(1e16, '.', thousand_sep=',', grouping=3, force_grouping=True),
+ '10,000,000,000,000,000',
+ )
+ self.assertEqual(
+ nformat(1e16, '.', decimal_pos=2, thousand_sep=',', grouping=3, force_grouping=True),
+ '10,000,000,000,000,000.00',
+ )
def test_decimal_numbers(self):
self.assertEqual(nformat(Decimal('1234'), '.'), '1234')