elif tag_type == 'end':
# Then check to see if the last opened section
# is the same as us
- last_section = open_sections.pop()
+ try:
+ last_section = open_sections.pop()
+ except IndexError:
+ raise ChevronError('Trying to close tag "{0}"\n'
+ 'Looks like it was not opened.\n'
+ 'line {1}'
+ .format(tag_key, _CURRENT_LINE + 1))
if tag_key != last_section:
# Otherwise we need to complain
raise ChevronError('Trying to close tag "{0}"\n'
except chevron.ChevronError as error:
self.assertEqual(error.msg, 'unclosed tag at line 3')
+ def test_no_opening_tag(self):
+ args = {
+ 'template': 'oops, no opening tag {{/ closing_tag }}',
+ 'data': {'foo': 'xx'}
+ }
+
+ try:
+ chevron.render(**args)
+ except chevron.ChevronError as error:
+ self.assertEqual(error.msg, 'Trying to close tag "closing_tag"\n'
+ 'Looks like it was not opened.\n'
+ 'line 2')
+
# Run unit tests from command line
if __name__ == "__main__":