summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_locale.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-04-13 08:09:50 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-04-13 08:09:50 (GMT)
commit88ad12afacb2b08b5d675be61f47c9244fba6825 (patch)
tree11c33f6da93ea64129a0e465a95e0326372e3662 /Lib/test/test_locale.py
parent613b2222cf859561adf00ebd5f67d3fc9738f752 (diff)
downloadcpython-88ad12afacb2b08b5d675be61f47c9244fba6825.zip
cpython-88ad12afacb2b08b5d675be61f47c9244fba6825.tar.gz
cpython-88ad12afacb2b08b5d675be61f47c9244fba6825.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_locale.py')
-rw-r--r--Lib/test/test_locale.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
new file mode 100644
index 0000000..4fb042a
--- /dev/null
+++ b/Lib/test/test_locale.py
@@ -0,0 +1,37 @@
+from test_support import verbose
+import locale
+
+oldlocale = locale.setlocale(locale.LC_NUMERIC)
+
+try:
+ 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)),
+ 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)