summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_locale.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-04-27 02:45:53 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-04-27 02:45:53 (GMT)
commitad78d15acc3db9918a115b7b7ed547ba815e3097 (patch)
tree1cf512e845342884e0dc187974d9be6e68b70a5d /Lib/test/test_locale.py
parent469b1f0d502756f049af8c26fca96bb85275a324 (diff)
downloadcpython-ad78d15acc3db9918a115b7b7ed547ba815e3097.zip
cpython-ad78d15acc3db9918a115b7b7ed547ba815e3097.tar.gz
cpython-ad78d15acc3db9918a115b7b7ed547ba815e3097.tar.bz2
Merged revisions 80512 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80512 | r.david.murray | 2010-04-26 17:17:14 -0400 (Mon, 26 Apr 2010) | 7 lines Issue #6656: fix locale.format_string to handle escaped percents and mappings. Refactors format_string. Includes tests for the two problems noted in the issue, but as far as I can see there are no other tests that confirm that format_string conforms to normal % formatting rules. ........
Diffstat (limited to 'Lib/test/test_locale.py')
-rw-r--r--Lib/test/test_locale.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 9439522..6cdb67b 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -236,6 +236,25 @@ class TestFormatPatternArg(unittest.TestCase):
self.assertRaises(ValueError, locale.format, " %f", 'foo')
self.assertRaises(ValueError, locale.format, "%fg", 'foo')
self.assertRaises(ValueError, locale.format, "%^g", 'foo')
+ self.assertRaises(ValueError, locale.format, "%f%%", 'foo')
+
+
+class TestLocaleFormatString(unittest.TestCase):
+ """General tests on locale.format_string"""
+
+ def test_percent_escape(self):
+ self.assertEqual(locale.format_string('%f%%', 1.0), '%f%%' % 1.0)
+ self.assertEqual(locale.format_string('%d %f%%d', (1, 1.0)),
+ '%d %f%%d' % (1, 1.0))
+ self.assertEqual(locale.format_string('%(foo)s %%d', {'foo': 'bar'}),
+ ('%(foo)s %%d' % {'foo': 'bar'}))
+
+ def test_mapping(self):
+ self.assertEqual(locale.format_string('%(foo)s bing.', {'foo': 'bar'}),
+ ('%(foo)s bing.' % {'foo': 'bar'}))
+ self.assertEqual(locale.format_string('%(foo)s', {'foo': 'bar'}),
+ ('%(foo)s' % {'foo': 'bar'}))
+
class TestNumberFormatting(BaseLocalizedTest, EnUSNumberFormatting):
@@ -377,6 +396,7 @@ def test_main():
tests = [
TestMiscellaneous,
TestFormatPatternArg,
+ TestLocaleFormatString,
TestEnUSNumberFormatting,
TestCNumberFormatting,
TestFrFRNumberFormatting,