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

Method test_is_valid

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

Source from the content-addressed store, hash-verified

503 'tim likes to eat a bag of ham worth $100')
504
505 def test_is_valid(self):
506 eq = self.assertEqual
507 s = Template('$who likes to eat a bag of ${what} worth $$100')
508 self.assertTrue(s.is_valid())
509
510 s = Template('$who likes to eat a bag of ${what} worth $100')
511 self.assertFalse(s.is_valid())
512
513 # if the pattern has an unrecognized capture group,
514 # it should raise ValueError like substitute and safe_substitute do
515 class BadPattern(Template):
516 pattern = r"""
517 (?P<badname>.*) |
518 (?P<escaped>@{2}) |
519 @(?P<named>[_a-z][._a-z0-9]*) |
520 @{(?P<braced>[_a-z][._a-z0-9]*)} |
521 (?P<invalid>@) |
522 """
523 s = BadPattern('@bag.foo.who likes to eat a bag of @bag.what')
524 self.assertRaises(ValueError, s.is_valid)
525
526 def test_get_identifiers(self):
527 eq = self.assertEqual

Callers

nothing calls this directly

Calls 6

TemplateClass · 0.90
BadPatternClass · 0.85
assertTrueMethod · 0.80
is_validMethod · 0.80
assertFalseMethod · 0.80
assertRaisesMethod · 0.45

Tested by

no test coverage detected