diff -r 2c4448bbed1f Lib/test/test_string.py --- a/Lib/test/test_string.py Thu Feb 25 01:35:21 2016 +1100 +++ b/Lib/test/test_string.py Wed Feb 24 22:33:05 2016 -0500 @@ -1,5 +1,5 @@ import unittest, string - +from string import Template class ModuleTest(unittest.TestCase): @@ -186,6 +186,18 @@ fmt._vformat("{i}", args, kwargs, set(), -1) self.assertIn("recursion", str(err.exception)) + def test_substitute(self): + temp = Template('$abc 456 $xyz') + sub = dict(abc='123', xyz='789') + self.assertEqual(temp.substitute(sub), '123 456 789') + self.assertEqual(temp.safe_substitute(sub), '123 456 789') + temp = Template('abc $456 $xyz') + with self.assertRaises(ValueError): + temp.substitute(sub) + temp = Template('$abc 456 $xyz $extra') + with self.assertRaises(KeyError): + temp.substitute(sub) + self.assertEqual(temp.safe_substitute(sub), '123 456 789 $extra') if __name__ == "__main__": unittest.main()