summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-04-01 03:21:43 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-04-01 03:21:43 (GMT)
commita83da3507f6f6075cce143cb118d3ddb23df981c (patch)
tree75e643486900e3c7547e16c70b92dd98fbf346e9 /Lib/test
parentbb94d43dcdbfddff40f23944f0e4079f41a30421 (diff)
downloadcpython-a83da3507f6f6075cce143cb118d3ddb23df981c.zip
cpython-a83da3507f6f6075cce143cb118d3ddb23df981c.tar.gz
cpython-a83da3507f6f6075cce143cb118d3ddb23df981c.tar.bz2
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_locale.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 180f403..d9d3cd9 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -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,