Outdent only if raise has been indented in multiple inheritance error handling. #83

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+18 −2
Split
View
@@ -894,12 +894,13 @@ def visit_Extends(self, node, frame):
self.indent()
self.writeline('raise TemplateRuntimeError(%r)' %
'extended multiple times')
- self.outdent()
# if we have a known extends already we don't need that code here
# as we know that the template execution will end here.
if self.has_known_extends:
raise CompilerExit()
+ else:
+ self.outdent()
self.writeline('parent_template = environment.get_template(', node)
self.visit(node.template, frame)
@@ -13,7 +13,7 @@
from jinja2.testsuite import JinjaTestCase
from jinja2 import Environment, DictLoader
-
+from jinja2.exceptions import TemplateRuntimeError
LAYOUTTEMPLATE = '''\
|{% block block1 %}block 1 from layout{% endblock %}
@@ -141,6 +141,21 @@ def test_multi_inheritance(self):
assert tmpl.render(master='master1') == 'MASTER1CHILD'
assert tmpl.render() == 'MASTER1CHILD'
+ def test_forbidden_multi_inheritance(self):
+ env = Environment(loader=DictLoader({
+ 'master1': '1',
+ 'master2': '2',
+ 'child': "{% extends 'master1' %}{% extends 'master2' %}"
+ }))
+
+ tmpl = env.get_template('child')
+ try:
+ tmpl.render()
+ except TemplateRuntimeError, e:
+ assert e.message == 'extended multiple times'
+ else:
+ assert False, 'Must raise on multiple inheritance'
+
def test_scoped_block(self):
env = Environment(loader=DictLoader({
'master.html': '{% for item in seq %}[{% block item scoped %}'