MCPcopy Index your code
hub / github.com/python/cpython / test_braced_override

Method test_braced_override

Lib/test/test_string/test_string.py:388–403  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

386 self.assertRaises(ValueError, s.safe_substitute, {})
387
388 def test_braced_override(self):
389 class MyTemplate(Template):
390 pattern = r"""
391 \$(?:
392 (?P<escaped>$) |
393 (?P<named>[_a-z][_a-z0-9]*) |
394 @@(?P<braced>[_a-z][_a-z0-9]*)@@ |
395 (?P<invalid>) |
396 )
397 """
398
399 tmpl = 'PyCon in $@@location@@'
400 t = MyTemplate(tmpl)
401 self.assertRaises(KeyError, t.substitute, {})
402 val = t.substitute({'location': 'Cleveland'})
403 self.assertEqual(val, 'PyCon in Cleveland')
404
405 def test_braced_override_safe(self):
406 class MyTemplate(Template):

Callers

nothing calls this directly

Calls 4

MyTemplateClass · 0.85
substituteMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected