blob: 4fb042a79985c5eaa0cabd4eb105cf08442daa11 [file] [log] [blame]
Martin v. Löwis88ad12a2001-04-13 08:09:50 +00001from test_support import verbose
2import locale
3
4oldlocale = locale.setlocale(locale.LC_NUMERIC)
5
6try:
7 locale.setlocale(locale.LC_NUMERIC, "en_US")
8except locale.Error:
9 raise ImportError, "test locale en_US not supported"
10
11def 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
28try:
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 ')
36finally:
37 locale.setlocale(locale.LC_NUMERIC, oldlocale)