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

Method test_get_identifiers

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

Source from the content-addressed store, hash-verified

524 self.assertRaises(ValueError, s.is_valid)
525
526 def test_get_identifiers(self):
527 eq = self.assertEqual
528 raises = self.assertRaises
529 s = Template('$who likes to eat a bag of ${what} worth $$100')
530 ids = s.get_identifiers()
531 eq(ids, ['who', 'what'])
532
533 # repeated identifiers only included once
534 s = Template('$who likes to eat a bag of ${what} worth $$100; ${who} likes to eat a bag of $what worth $$100')
535 ids = s.get_identifiers()
536 eq(ids, ['who', 'what'])
537
538 # invalid identifiers are ignored
539 s = Template('$who likes to eat a bag of ${what} worth $100')
540 ids = s.get_identifiers()
541 eq(ids, ['who', 'what'])
542
543 # if the pattern has an unrecognized capture group,
544 # it should raise ValueError like substitute and safe_substitute do
545 class BadPattern(Template):
546 pattern = r"""
547 (?P<badname>.*) |
548 (?P<escaped>@{2}) |
549 @(?P<named>[_a-z][._a-z0-9]*) |
550 @{(?P<braced>[_a-z][._a-z0-9]*)} |
551 (?P<invalid>@) |
552 """
553 s = BadPattern('@bag.foo.who likes to eat a bag of @bag.what')
554 self.assertRaises(ValueError, s.get_identifiers)
555
556
557if __name__ == '__main__':

Callers

nothing calls this directly

Calls 5

TemplateClass · 0.90
eqFunction · 0.85
BadPatternClass · 0.85
get_identifiersMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected