mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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.
This commit is contained in:
parent
278d665c6a
commit
3939dcdb72
3 changed files with 45 additions and 14 deletions
|
@ -238,6 +238,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):
|
||||
|
@ -382,6 +401,7 @@ def test_main():
|
|||
tests = [
|
||||
TestMiscellaneous,
|
||||
TestFormatPatternArg,
|
||||
TestLocaleFormatString,
|
||||
TestEnUSNumberFormatting,
|
||||
TestCNumberFormatting,
|
||||
TestFrFRNumberFormatting,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue