summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pep292.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-14 02:34:08 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-14 02:34:08 (GMT)
commit6d191113a6c24c5a5c1cd8ade63f5a8f7027b1f4 (patch)
tree098a5dafc4215acc8bcb4e07f762b92552ab98ff /Lib/test/test_pep292.py
parent23f1241dc6495eb255e1a389aef204a3e35a2632 (diff)
downloadcpython-6d191113a6c24c5a5c1cd8ade63f5a8f7027b1f4.zip
cpython-6d191113a6c24c5a5c1cd8ade63f5a8f7027b1f4.tar.gz
cpython-6d191113a6c24c5a5c1cd8ade63f5a8f7027b1f4.tar.bz2
Fix small bugs in Template code.
* The parameterization of "delimiter" was incomplete. * safe_substitute's code for braced delimiters should only be executed when braced is not None. * Invalid pattern group names now raise a ValueError. Formerly, the convert code would fall off the end and improperly return None. Beefed-up tests. * Test delimiter override for all paths in substitute and safe_substitute. * Alter unittest invocation to match other modules (now it itemizes the tests as they are run).
Diffstat (limited to 'Lib/test/test_pep292.py')
-rw-r--r--Lib/test/test_pep292.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py
index c22f59b..f955774 100644
--- a/Lib/test/test_pep292.py
+++ b/Lib/test/test_pep292.py
@@ -150,17 +150,27 @@ class TestTemplate(unittest.TestCase):
raises(TypeError, s.substitute, d, {})
raises(TypeError, s.safe_substitute, d, {})
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestTemplate))
- return suite
-
+ def test_delimiter_override(self):
+ class AmpersandTemplate(Template):
+ delimiter = '&'
+ s = AmpersandTemplate('this &gift is for &{who} &&')
+ self.assertEqual(s.substitute(gift='bud', who='you'),
+ 'this bud is for you &')
+ self.assertRaises(KeyError, s.substitute)
+ self.assertEqual(s.safe_substitute(gift='bud', who='you'),
+ 'this bud is for you &')
+ self.assertEqual(s.safe_substitute(),
+ 'this &gift is for &{who} &')
+ s = AmpersandTemplate('this &gift is for &{who} &')
+ self.assertRaises(ValueError, s.substitute,
+ dict(gift='bud', who='you'))
+ self.assertRaises(ValueError, s.safe_substitute)
def test_main():
from test import test_support
- test_support.run_suite(suite())
+ test_classes = [TestTemplate,]
+ test_support.run_unittest(*test_classes)
if __name__ == '__main__':
- unittest.main()
+ test_main()