summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_string.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-24 20:28:43 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-24 20:28:43 (GMT)
commit8ffe917cee26b83fed4f227c4ed16d4eec15dcf9 (patch)
tree3a2bbef671dcda71bfa36cf5a02d4b68d09cb98a /Lib/test/test_string.py
parentbe1eb1424121682081fed8996e87e2dfd238e7ea (diff)
downloadcpython-8ffe917cee26b83fed4f227c4ed16d4eec15dcf9.zip
cpython-8ffe917cee26b83fed4f227c4ed16d4eec15dcf9.tar.gz
cpython-8ffe917cee26b83fed4f227c4ed16d4eec15dcf9.tar.bz2
Issue #23671: string.Template now allows to specify the "self" parameter as
keyword argument. string.Formatter now allows to specify the "self" and the "format_string" parameters as keyword arguments.
Diffstat (limited to 'Lib/test/test_string.py')
-rw-r--r--Lib/test/test_string.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index 3e65071..30fe42a 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -31,6 +31,20 @@ class ModuleTest(unittest.TestCase):
self.assertEqual(fmt.format("foo"), "foo")
self.assertEqual(fmt.format("foo{0}", "bar"), "foobar")
self.assertEqual(fmt.format("foo{1}{0}-{1}", "bar", 6), "foo6bar-6")
+ self.assertRaises(TypeError, fmt.format)
+ self.assertRaises(TypeError, string.Formatter.format)
+
+ def test_format_keyword_arguments(self):
+ fmt = string.Formatter()
+ self.assertEqual(fmt.format("-{arg}-", arg='test'), '-test-')
+ self.assertRaises(KeyError, fmt.format, "-{arg}-")
+ self.assertEqual(fmt.format("-{self}-", self='test'), '-test-')
+ self.assertRaises(KeyError, fmt.format, "-{self}-")
+ self.assertEqual(fmt.format("-{format_string}-", format_string='test'),
+ '-test-')
+ self.assertRaises(KeyError, fmt.format, "-{format_string}-")
+ self.assertEqual(fmt.format(arg='test', format_string="-{arg}-"),
+ '-test-')
def test_auto_numbering(self):
fmt = string.Formatter()