Kaydet (Commit) 0a95063d authored tarafından Eric Smith's avatar Eric Smith

Issue 2526, float.__format__ 'n' specifier does not support thousands grouping.

Implemented grouping, with tests.
Cleaned up PyOS_ascii_formatd by breaking reformatting into smaller functions.
üst 48f6276d
# Python test set -- part 6, built-in types
from test.test_support import run_unittest, have_unicode
from test.test_support import run_unittest, have_unicode, run_with_locale
import unittest
import sys
import locale
class TypesTests(unittest.TestCase):
......@@ -476,6 +477,15 @@ class TypesTests(unittest.TestCase):
self.assertEqual(value.__format__(format_spec),
float(value).__format__(format_spec))
@run_with_locale('LC_NUMERIC', 'en_US.UTF8')
def test_float__format__locale(self):
# test locale support for __format__ code 'n'
for i in range(-10, 10):
x = 1234567890.0 * (10.0 ** i)
self.assertEqual(locale.format('%g', x, grouping=True), format(x, 'n'))
self.assertEqual(locale.format('%.10g', x, grouping=True), format(x, '.10n'))
def test_float__format__(self):
# these should be rewritten to use both format(x, spec) and
# x.__format__(spec)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment