mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Fix issue 2522. locale.format now checks that it is passed
exactly one pattern, which avoids mysterious errors where it had seemed to fail to do localization.
This commit is contained in:
parent
bb94d43dcd
commit
a83da3507f
4 changed files with 35 additions and 8 deletions
|
@ -221,6 +221,19 @@ class EnUSNumberFormatting(BaseFormattingTest):
|
|||
(self.sep, self.sep))
|
||||
|
||||
|
||||
class TestFormatPatternArg(unittest.TestCase):
|
||||
# Test handling of pattern argument of format
|
||||
|
||||
def test_onlyOnePattern(self):
|
||||
# Issue 2522: accept exactly one % pattern, and no extra chars.
|
||||
self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
|
||||
self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
|
||||
self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
|
||||
self.assertRaises(ValueError, locale.format, " %f", 'foo')
|
||||
self.assertRaises(ValueError, locale.format, "%fg", 'foo')
|
||||
self.assertRaises(ValueError, locale.format, "%^g", 'foo')
|
||||
|
||||
|
||||
class TestNumberFormatting(BaseLocalizedTest, EnUSNumberFormatting):
|
||||
# Test number formatting with a real English locale.
|
||||
|
||||
|
@ -351,6 +364,7 @@ class TestMiscellaneous(unittest.TestCase):
|
|||
def test_main():
|
||||
tests = [
|
||||
TestMiscellaneous,
|
||||
TestFormatPatternArg,
|
||||
TestEnUSNumberFormatting,
|
||||
TestCNumberFormatting,
|
||||
TestFrFRNumberFormatting,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue