Fixed #79
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 9417d01 · Browse files · 2 files·+27 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+27 added−3 removed
- other:+27 added−3 removed
Provenance
- Commit
400f973- Tree
285119b- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
9417d01
2 files changed+27 added−3 removed
modified:jinja2/testsuite/inheritance.py+25 added-2 removed
10 unmodified lines11 import unittest12 13 from jinja2.testsuite import JinjaTestCase14 15-from jinja2 import Environment, DictLoader15+from jinja2 import Environment, DictLoader, TemplateError16 17 18 LAYOUTTEMPLATE = '''\19 |{% block block1 %}block 1 from layout{% endblock %}32 unmodified lines52 {% endif %}53 {% endblock %}54 '''55 56+DOUBLEEXTENDS = '''\57+{% extends "layout" %}58+{% extends "layout" %}59+{% block block1 %}60+ {% if false %}61+ {% block block2 %}62+ this should workd63+ {% endblock %}64+ {% endif %}65+{% endblock %}66+'''67+68+69 env = Environment(loader=DictLoader({70 'layout': LAYOUTTEMPLATE,71 'level1': LEVEL1TEMPLATE,72 'level2': LEVEL2TEMPLATE,73 'level3': LEVEL3TEMPLATE,74 'level4': LEVEL4TEMPLATE,62- 'working': WORKINGTEMPLATE75+ 'working': WORKINGTEMPLATE,76+ 'doublee': DOUBLEEXTENDS,77 }), trim_blocks=True)78 79 80 class InheritanceTestCase(JinjaTestCase):151 unmodified lines232 {% block content %} {% endblock %}233 '''234 })).get_template("test.html").render().split() == [u'outer_box', u'my_macro']235 236+ def test_double_extends(self):237+ """Ensures that a template with more than 1 {% extends ... %} usage238+ raises a ``TemplateError``.239+ """240+ try:241+ tmpl = env.get_template('doublee')242+ except Exception, e:243+ assert isinstance(e, TemplateError)244 245+246 def suite():247 suite = unittest.TestSuite()248 suite.addTest(unittest.makeSuite(InheritanceTestCase))249 suite.addTest(unittest.makeSuite(BugFixTestCase))1 unmodified linemodified:jinja2/compiler.py+2 added-1 removed
890 unmodified lines891 self.writeline('if parent_template is not None:')892 self.indent()893 self.writeline('raise TemplateRuntimeError(%r)' %894 'extended multiple times')895- self.outdent()895 896 # if we have a known extends already we don't need that code here897 # as we know that the template execution will end here.898 if self.has_known_extends:899 raise CompilerExit()900+ else:901+ self.outdent()902 903 self.writeline('parent_template = environment.get_template(', node)904 self.visit(node.template, frame)905 self.write(', %r)' % self.name)735 unmodified lines