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

Method test_delimiter_override

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

Source from the content-addressed store, hash-verified

483 eq(s.safe_substitute(self='bozo'), 'the self is bozo')
484
485 def test_delimiter_override(self):
486 eq = self.assertEqual
487 raises = self.assertRaises
488 class AmpersandTemplate(Template):
489 delimiter = '&'
490 s = AmpersandTemplate('this &gift is for &{who} &&')
491 eq(s.substitute(gift='bud', who='you'), 'this bud is for you &')
492 raises(KeyError, s.substitute)
493 eq(s.safe_substitute(gift='bud', who='you'), 'this bud is for you &')
494 eq(s.safe_substitute(), 'this &gift is for &{who} &')
495 s = AmpersandTemplate('this &gift is for &{who} &')
496 raises(ValueError, s.substitute, dict(gift='bud', who='you'))
497 eq(s.safe_substitute(), 'this &gift is for &{who} &')
498
499 class PieDelims(Template):
500 delimiter = '@'
501 s = PieDelims('@who likes to eat a bag of @{what} worth $100')
502 self.assertEqual(s.substitute(dict(who='tim', what='ham')),
503 'tim likes to eat a bag of ham worth $100')
504
505 def test_is_valid(self):
506 eq = self.assertEqual

Callers

nothing calls this directly

Calls 7

AmpersandTemplateClass · 0.85
eqFunction · 0.85
raisesFunction · 0.85
PieDelimsClass · 0.85
substituteMethod · 0.80
safe_substituteMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected