diff options
author | Barry Warsaw <barry@python.org> | 2004-09-13 14:35:59 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2004-09-13 14:35:59 (GMT) |
commit | 302bd589ad22481795a8a34eceb66dabcfd6a2d6 (patch) | |
tree | 4b5f000e879b5fb377819f317821f93c376233e8 | |
parent | 46b629c10164e89799a265f9a11b99c39efaee51 (diff) | |
download | cpython-302bd589ad22481795a8a34eceb66dabcfd6a2d6.zip cpython-302bd589ad22481795a8a34eceb66dabcfd6a2d6.tar.gz cpython-302bd589ad22481795a8a34eceb66dabcfd6a2d6.tar.bz2 |
Add tests for keyword arguments and combining mapping and keyword arguments.
-rw-r--r-- | Lib/test/test_pep292.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py index 56eb417..6c6aa9f 100644 --- a/Lib/test/test_pep292.py +++ b/Lib/test/test_pep292.py @@ -118,6 +118,34 @@ class TestTemplate(unittest.TestCase): d = dict(who=u't\xffm', what=u'f\xfe\fed') self.assertEqual(s.substitute(d), u't\xffm likes f\xfe\x0ced') + def test_keyword_arguments(self): + eq = self.assertEqual + s = Template('$who likes $what') + eq(s.substitute(who='tim', what='ham'), 'tim likes ham') + eq(s.substitute(dict(who='tim'), what='ham'), 'tim likes ham') + eq(s.substitute(dict(who='fred', what='kung pao'), + who='tim', what='ham'), + 'tim likes ham') + s = Template('the mapping is $mapping') + eq(s.substitute(dict(foo='none'), mapping='bozo'), + 'the mapping is bozo') + eq(s.substitute(dict(mapping='one'), mapping='two'), + 'the mapping is two') + + def test_keyword_arguments_safe(self): + eq = self.assertEqual + s = Template('$who likes $what') + eq(s.safe_substitute(who='tim', what='ham'), 'tim likes ham') + eq(s.safe_substitute(dict(who='tim'), what='ham'), 'tim likes ham') + eq(s.safe_substitute(dict(who='fred', what='kung pao'), + who='tim', what='ham'), + 'tim likes ham') + s = Template('the mapping is $mapping') + eq(s.safe_substitute(dict(foo='none'), mapping='bozo'), + 'the mapping is bozo') + eq(s.safe_substitute(dict(mapping='one'), mapping='two'), + 'the mapping is two') + def suite(): suite = unittest.TestSuite() |