Martin v. Löwis | 88ad12a | 2001-04-13 08:09:50 +0000 | [diff] [blame^] | 1 | from test_support import verbose |
| 2 | import locale |
| 3 | |
| 4 | oldlocale = locale.setlocale(locale.LC_NUMERIC) |
| 5 | |
| 6 | try: |
| 7 | locale.setlocale(locale.LC_NUMERIC, "en_US") |
| 8 | except locale.Error: |
| 9 | raise ImportError, "test locale en_US not supported" |
| 10 | |
| 11 | def testformat(formatstr, value, grouping = 0, output=None): |
| 12 | if verbose: |
| 13 | if output: |
| 14 | print "%s %% %s =? %s ..." %\ |
| 15 | (repr(formatstr), repr(value), repr(output)), |
| 16 | else: |
| 17 | print "%s %% %s works? ..." % (repr(formatstr), repr(value)), |
| 18 | result = locale.format(formatstr, value, grouping = grouping) |
| 19 | if output and result != output: |
| 20 | if verbose: |
| 21 | print 'no' |
| 22 | print "%s %% %s == %s != %s" %\ |
| 23 | (repr(formatstr), repr(value), repr(result), repr(output)) |
| 24 | else: |
| 25 | if verbose: |
| 26 | print "yes" |
| 27 | |
| 28 | try: |
| 29 | testformat("%f", 1024, grouping=1, output='1,024.000000') |
| 30 | testformat("%f", 102, grouping=1, output='102.000000') |
| 31 | testformat("%f", -42, grouping=1, output='-42.000000') |
| 32 | testformat("%+f", -42, grouping=1, output='-42.000000') |
| 33 | testformat("%20.f", -42, grouping=1, output=' -42') |
| 34 | testformat("%+10.f", -4200, grouping=1, output=' -4,200') |
| 35 | testformat("%-10.f", 4200, grouping=1, output='4,200 ') |
| 36 | finally: |
| 37 | locale.setlocale(locale.LC_NUMERIC, oldlocale) |