summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_locale.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-05-17 15:51:16 (GMT)
committerGeorg Brandl <georg@python.org>2006-05-17 15:51:16 (GMT)
commitb89316fdbf5d5d4d33ab780c5ce2ab006ebb6ea7 (patch)
tree109cd781e14cff9877c4d41a174dcb2a559350ab /Lib/test/test_locale.py
parent9d6da3e2f29344598178243bb519bc68ad8045b4 (diff)
downloadcpython-b89316fdbf5d5d4d33ab780c5ce2ab006ebb6ea7.zip
cpython-b89316fdbf5d5d4d33ab780c5ce2ab006ebb6ea7.tar.gz
cpython-b89316fdbf5d5d4d33ab780c5ce2ab006ebb6ea7.tar.bz2
Patch #1180296: improve locale string formatting functions
Diffstat (limited to 'Lib/test/test_locale.py')
-rw-r--r--Lib/test/test_locale.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 1523e77..ec5a533 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -20,14 +20,14 @@ for tloc in tlocs:
else:
raise ImportError, "test locale not supported (tried %s)"%(', '.join(tlocs))
-def testformat(formatstr, value, grouping = 0, output=None):
+def testformat(formatstr, value, grouping = 0, output=None, func=locale.format):
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)
+ result = func(formatstr, value, grouping = grouping)
if output and result != output:
if verbose:
print 'no'
@@ -49,6 +49,27 @@ try:
testformat("%-10.f", 4200, grouping=1, output='4%s200 ' % sep)
# Invoke getpreferredencoding to make sure it does not cause exceptions,
locale.getpreferredencoding()
+
+ # === Test format() with more complex formatting strings
+ # test if grouping is independent from other characters in formatting string
+ testformat("One million is %i", 1000000, grouping=1, output='One million is 1,000,000',
+ func=locale.format_string)
+ testformat("One million is %i", 1000000, grouping=1, output='One million is 1,000,000',
+ func=locale.format_string)
+ # test dots in formatting string
+ testformat(".%f.", 1000.0, output='.1000.000000.', func=locale.format_string)
+ # test floats
+ testformat("--> %10.2f", 1000.0, grouping=1, output='--> 1,000.00',
+ func=locale.format_string)
+ # test asterisk formats
+ testformat("%10.*f", (2, 1000.0), grouping=0, output=' 1000.00',
+ func=locale.format_string)
+ testformat("%*.*f", (10, 2, 1000.0), grouping=1, output=' 1,000.00',
+ func=locale.format_string)
+ # test more-in-one
+ testformat("int %i float %.2f str %s", (1000, 1000.0, 'str'), grouping=1,
+ output='int 1,000 float 1,000.00 str str', func=locale.format_string)
+
finally:
locale.setlocale(locale.LC_NUMERIC, oldlocale)