[Python-checkins] CVS: python/dist/src/Lib/test test_locale.py,NONE,1.1

Martin v. L?wis loewis@users.sourceforge.net
Fri, 13 Apr 2001 01:09:53 -0700

Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv4882/test

Added Files:
Log Message:
Patch #415777: new grouping strategy.
fixes bug #414940, and redoes the fix for #129417 in a different way.
It also fixes a number of other problems with locale-specific formatting:
If there is leading or trailing spaces, then no grouping should be applied
in the spaces, and the total length of the string should not be changed
due to grouping.
Also added test case which works only if the en_US locale is available.

--- NEW FILE: test_locale.py ---
from test_support import verbose
import locale

oldlocale = locale.setlocale(locale.LC_NUMERIC)

    locale.setlocale(locale.LC_NUMERIC, "en_US")
except locale.Error:
    raise ImportError, "test locale en_US not supported"

def testformat(formatstr, value, grouping = 0, output=None):
    if verbose:
        if output:
            print "%s %% %s =? %s ..." %\
                (repr(formatstr), repr(value), repr(output)),
            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))
        if verbose:
            print "yes"

    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     ')    
    locale.setlocale(locale.LC_NUMERIC, oldlocale)