mirror of
https://github.com/python/cpython.git
synced 2024-12-14 04:17:19 +08:00
04f357cffe
imports e.g. test_support must do so using an absolute package name such as "import test.test_support" or "from test import test_support". This also updates the README in Lib/test, and gets rid of the duplicate data dirctory in Lib/test/data (replaced by Lib/email/test/data). Now Tim and Jack can have at it. :)
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from test.test_support import verbose
|
|
import locale
|
|
import sys
|
|
|
|
oldlocale = locale.setlocale(locale.LC_NUMERIC)
|
|
|
|
tloc = "en_US"
|
|
if sys.platform[:3] == "win":
|
|
tloc = "en"
|
|
|
|
try:
|
|
locale.setlocale(locale.LC_NUMERIC, tloc)
|
|
except locale.Error:
|
|
raise ImportError, "test locale %s not supported" % tloc
|
|
|
|
def testformat(formatstr, value, grouping = 0, output=None):
|
|
if verbose:
|
|
if output:
|
|
print "%s %% %s =? %s ..." %\
|
|
(repr(formatstr), repr(value), repr(output)),
|
|
else:
|
|
print "%s %% %s works? ..." % (repr(formatstr), repr(value)),
|
|
result = locale.format(formatstr, value, grouping = grouping)
|
|
if output and result != output:
|
|
if verbose:
|
|
print 'no'
|
|
print "%s %% %s == %s != %s" %\
|
|
(repr(formatstr), repr(value), repr(result), repr(output))
|
|
else:
|
|
if verbose:
|
|
print "yes"
|
|
|
|
try:
|
|
testformat("%f", 1024, grouping=1, output='1,024.000000')
|
|
testformat("%f", 102, grouping=1, output='102.000000')
|
|
testformat("%f", -42, grouping=1, output='-42.000000')
|
|
testformat("%+f", -42, grouping=1, output='-42.000000')
|
|
testformat("%20.f", -42, grouping=1, output=' -42')
|
|
testformat("%+10.f", -4200, grouping=1, output=' -4,200')
|
|
testformat("%-10.f", 4200, grouping=1, output='4,200 ')
|
|
finally:
|
|
locale.setlocale(locale.LC_NUMERIC, oldlocale)
|