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

Method test_pattern_override

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

Source from the content-addressed store, hash-verified

358 self.assertRaises(ValueError, s.substitute, m)
359
360 def test_pattern_override(self):
361 class MyPattern(Template):
362 pattern = r"""
363 (?P<escaped>@{2}) |
364 @(?P<named>[_a-z][._a-z0-9]*) |
365 @{(?P<braced>[_a-z][._a-z0-9]*)} |
366 (?P<invalid>@)
367 """
368 m = Mapping()
369 m.bag = Bag()
370 m.bag.foo = Bag()
371 m.bag.foo.who = 'tim'
372 m.bag.what = 'ham'
373 s = MyPattern('@bag.foo.who likes to eat a bag of @bag.what')
374 self.assertEqual(s.substitute(m), 'tim likes to eat a bag of ham')
375
376 class BadPattern(Template):
377 pattern = r"""
378 (?P<badname>.*) |
379 (?P<escaped>@{2}) |
380 @(?P<named>[_a-z][._a-z0-9]*) |
381 @{(?P<braced>[_a-z][._a-z0-9]*)} |
382 (?P<invalid>@) |
383 """
384 s = BadPattern('@bag.foo.who likes to eat a bag of @bag.what')
385 self.assertRaises(ValueError, s.substitute, {})
386 self.assertRaises(ValueError, s.safe_substitute, {})
387
388 def test_braced_override(self):
389 class MyTemplate(Template):

Callers

nothing calls this directly

Calls 7

MyPatternClass · 0.85
BadPatternClass · 0.85
substituteMethod · 0.80
MappingClass · 0.70
BagClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected