(self)
| 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 | |
| 557 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected