summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/string.py2
-rw-r--r--Lib/test/test_pep292.py19
2 files changed, 10 insertions, 11 deletions
diff --git a/Lib/string.py b/Lib/string.py
index e10087e..7c0e001 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -199,7 +199,7 @@ class Template:
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
- self._invalid(mo)
+ return self.delimiter
raise ValueError('Unrecognized named group in pattern',
self.pattern)
return self.pattern.sub(convert, self.template)
diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py
index 19952e4..2a4353a 100644
--- a/Lib/test/test_pep292.py
+++ b/Lib/test/test_pep292.py
@@ -163,20 +163,19 @@ class TestTemplate(unittest.TestCase):
raises(TypeError, s.safe_substitute, d, {})
def test_delimiter_override(self):
+ eq = self.assertEqual
+ raises = self.assertRaises
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} &')
+ eq(s.substitute(gift='bud', who='you'), 'this bud is for you &')
+ raises(KeyError, s.substitute)
+ eq(s.safe_substitute(gift='bud', who='you'), 'this bud is for you &')
+ eq(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)
+ raises(ValueError, s.substitute, dict(gift='bud', who='you'))
+ eq(s.safe_substitute(), 'this &gift is for &{who} &')
+
def test_main():
from test import test_support