diff options
| author | Eric Smith <eric@trueblade.com> | 2008-05-11 19:52:48 (GMT) |
|---|---|---|
| committer | Eric Smith <eric@trueblade.com> | 2008-05-11 19:52:48 (GMT) |
| commit | cf537ff39ea1a518e937ee607bce816e8f3f41b6 (patch) | |
| tree | 4ce4b95ac5aaa8b26bf8899ac668acd14624c0c8 /Lib/test | |
| parent | 30ece44f2e5397e8501380349fd5278e6f64f555 (diff) | |
| download | cpython-cf537ff39ea1a518e937ee607bce816e8f3f41b6.zip cpython-cf537ff39ea1a518e937ee607bce816e8f3f41b6.tar.gz cpython-cf537ff39ea1a518e937ee607bce816e8f3f41b6.tar.bz2 | |
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_types.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 4b620c5..aca5ff2 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -377,7 +377,7 @@ class TypesTests(unittest.TestCase): # ensure that float type specifiers work; format converts # the int to a float - for format_spec in 'eEfFgGn%': + for format_spec in 'eEfFgG%': for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]: self.assertEqual(value.__format__(format_spec), float(value).__format__(format_spec)) @@ -472,7 +472,7 @@ class TypesTests(unittest.TestCase): # ensure that float type specifiers work; format converts # the long to a float - for format_spec in 'eEfFgGn%': + for format_spec in 'eEfFgG%': for value in [0L, 1L, -1L, 100L, -100L, 1234567890L, -1234567890L]: self.assertEqual(value.__format__(format_spec), float(value).__format__(format_spec)) @@ -486,6 +486,17 @@ class TypesTests(unittest.TestCase): self.assertEqual(locale.format('%g', x, grouping=True), format(x, 'n')) self.assertEqual(locale.format('%.10g', x, grouping=True), format(x, '.10n')) + @run_with_locale('LC_NUMERIC', 'en_US.UTF8') + def test_int__format__locale(self): + # test locale support for __format__ code 'n' for integers + + x = 123456789012345678901234567890 + for i in range(0, 30): + self.assertEqual(locale.format('%d', x, grouping=True), format(x, 'n')) + + # move to the next integer to test + x = x // 10 + def test_float__format__(self): # these should be rewritten to use both format(x, spec) and # x.__format__(spec) |
