diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-03-14 00:13:13 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-03-14 00:13:13 (GMT) |
commit | 350370c25fd1259199bb18fbce9fa447cd02ddf1 (patch) | |
tree | 2355fa9c5041ae14ee37170234ffbfe943b25e27 /Lib/test/test_locale.py | |
parent | a28fcfdbdaa082a8d3849d7dc829f89cd7f868a8 (diff) | |
download | cpython-350370c25fd1259199bb18fbce9fa447cd02ddf1.zip cpython-350370c25fd1259199bb18fbce9fa447cd02ddf1.tar.gz cpython-350370c25fd1259199bb18fbce9fa447cd02ddf1.tar.bz2 |
Merged revisions 70356 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70356 | antoine.pitrou | 2009-03-14 01:07:21 +0100 (sam., 14 mars 2009) | 3 lines
Issue #1222: locale.format() bug when the thousands separator is a space character.
........
Diffstat (limited to 'Lib/test/test_locale.py')
-rw-r--r-- | Lib/test/test_locale.py | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index 0858b60..7fc6372 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -103,6 +103,32 @@ class EnUSCookedTest(BaseCookedTest): } +class FrFRCookedTest(BaseCookedTest): + # A cooked "fr_FR" locale with a space character as decimal separator + # and a non-ASCII currency symbol. + + cooked_values = { + 'currency_symbol': '\u20ac', + 'decimal_point': ',', + 'frac_digits': 2, + 'grouping': [3, 3, 0], + 'int_curr_symbol': 'EUR ', + 'int_frac_digits': 2, + 'mon_decimal_point': ',', + 'mon_grouping': [3, 3, 0], + 'mon_thousands_sep': ' ', + 'n_cs_precedes': 0, + 'n_sep_by_space': 1, + 'n_sign_posn': 1, + 'negative_sign': '-', + 'p_cs_precedes': 0, + 'p_sep_by_space': 1, + 'p_sign_posn': 1, + 'positive_sign': '', + 'thousands_sep': ' ' + } + + class BaseFormattingTest(object): # # Utility functions for formatting tests @@ -150,6 +176,12 @@ class EnUSNumberFormatting(BaseFormattingTest): self._test_format("%+d", 4200, grouping=True, out='+4%s200' % self.sep) self._test_format("%+d", -4200, grouping=True, out='-4%s200' % self.sep) + def test_integer_grouping_and_padding(self): + self._test_format("%10d", 4200, grouping=True, + out=('4%s200' % self.sep).rjust(10)) + self._test_format("%-10d", -4200, grouping=True, + out=('-4%s200' % self.sep).ljust(10)) + def test_simple(self): self._test_format("%f", 1024, grouping=0, out='1024.000000') self._test_format("%f", 102, grouping=0, out='102.000000') @@ -221,6 +253,49 @@ class TestCNumberFormatting(CCookedTest, BaseFormattingTest): self._test_format("%9.2f", 12345.67, grouping=True, out=' 12345.67') +class TestFrFRNumberFormatting(FrFRCookedTest, BaseFormattingTest): + # Test number formatting with a cooked "fr_FR" locale. + + def test_decimal_point(self): + self._test_format("%.2f", 12345.67, out='12345,67') + + def test_grouping(self): + self._test_format("%.2f", 345.67, grouping=True, out='345,67') + self._test_format("%.2f", 12345.67, grouping=True, out='12 345,67') + + def test_grouping_and_padding(self): + self._test_format("%6.2f", 345.67, grouping=True, out='345,67') + self._test_format("%7.2f", 345.67, grouping=True, out=' 345,67') + self._test_format("%8.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format("%9.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format("%10.2f", 12345.67, grouping=True, out=' 12 345,67') + self._test_format("%-6.2f", 345.67, grouping=True, out='345,67') + self._test_format("%-7.2f", 345.67, grouping=True, out='345,67 ') + self._test_format("%-8.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format("%-9.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format("%-10.2f", 12345.67, grouping=True, out='12 345,67 ') + + def test_integer_grouping(self): + self._test_format("%d", 200, grouping=True, out='200') + self._test_format("%d", 4200, grouping=True, out='4 200') + + def test_integer_grouping_and_padding(self): + self._test_format("%4d", 4200, grouping=True, out='4 200') + self._test_format("%5d", 4200, grouping=True, out='4 200') + self._test_format("%10d", 4200, grouping=True, out='4 200'.rjust(10)) + self._test_format("%-4d", 4200, grouping=True, out='4 200') + self._test_format("%-5d", 4200, grouping=True, out='4 200') + self._test_format("%-10d", 4200, grouping=True, out='4 200'.ljust(10)) + + def test_currency(self): + euro = '\u20ac' + self._test_currency(50000, "50000,00 " + euro) + self._test_currency(50000, "50 000,00 " + euro, grouping=True) + # XXX is the trailing space a bug? + self._test_currency(50000, "50 000,00 EUR ", + grouping=True, international=True) + + class TestMiscellaneous(unittest.TestCase): def test_getpreferredencoding(self): # Invoke getpreferredencoding to make sure it does not cause exceptions. @@ -240,7 +315,8 @@ def test_main(): tests = [ TestMiscellaneous, TestEnUSNumberFormatting, - TestCNumberFormatting + TestCNumberFormatting, + TestFrFRNumberFormatting, ] # TestSkipped can't be raised inside unittests, handle it manually instead try: |