1 from test
.test_support
import verbose
, TestSkipped
5 if sys
.platform
== 'darwin':
6 raise TestSkipped("Locale support on MacOSX is minimal and cannot be tested")
7 oldlocale
= locale
.setlocale(locale
.LC_NUMERIC
)
10 if sys
.platform
[:3] == "win":
14 locale
.setlocale(locale
.LC_NUMERIC
, tloc
)
16 raise ImportError, "test locale %s not supported" % tloc
18 def testformat(formatstr
, value
, grouping
= 0, output
=None):
21 print "%s %% %s =? %s ..." %\
22 (repr(formatstr
), repr(value
), repr(output
)),
24 print "%s %% %s works? ..." % (repr(formatstr
), repr(value
)),
25 result
= locale
.format(formatstr
, value
, grouping
= grouping
)
26 if output
and result
!= output
:
29 print "%s %% %s == %s != %s" %\
30 (repr(formatstr
), repr(value
), repr(result
), repr(output
))
36 testformat("%f", 1024, grouping
=1, output
='1,024.000000')
37 testformat("%f", 102, grouping
=1, output
='102.000000')
38 testformat("%f", -42, grouping
=1, output
='-42.000000')
39 testformat("%+f", -42, grouping
=1, output
='-42.000000')
40 testformat("%20.f", -42, grouping
=1, output
=' -42')
41 testformat("%+10.f", -4200, grouping
=1, output
=' -4,200')
42 testformat("%-10.f", 4200, grouping
=1, output
='4,200 ')
43 # Invoke getpreferredencoding to make sure it does not cause exceptions,
44 locale
.getpreferredencoding()
46 locale
.setlocale(locale
.LC_NUMERIC
, oldlocale
)