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

Method test_SafeTemplate

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

Source from the content-addressed store, hash-verified

288 eq(s.safe_substitute(d), "('tim', 'fred') ate ('ham', 'kung pao')")
289
290 def test_SafeTemplate(self):
291 eq = self.assertEqual
292 s = Template('$who likes ${what} for ${meal}')
293 eq(s.safe_substitute(dict(who='tim')), 'tim likes ${what} for ${meal}')
294 eq(s.safe_substitute(dict(what='ham')), '$who likes ham for ${meal}')
295 eq(s.safe_substitute(dict(what='ham', meal='dinner')),
296 '$who likes ham for dinner')
297 eq(s.safe_substitute(dict(who='tim', what='ham')),
298 'tim likes ham for ${meal}')
299 eq(s.safe_substitute(dict(who='tim', what='ham', meal='dinner')),
300 'tim likes ham for dinner')
301
302 def test_invalid_placeholders(self):
303 raises = self.assertRaises

Callers

nothing calls this directly

Calls 3

safe_substituteMethod · 0.95
TemplateClass · 0.90
eqFunction · 0.85

Tested by

no test coverage detected