Fixed imports with scoped blocks
authorArmin Ronacher <armin.ronacher@active-4.com>
Wed, 22 Dec 2010 22:22:08 +0000 (23:22 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Wed, 22 Dec 2010 22:22:08 +0000 (23:22 +0100)
CHANGES
jinja2/runtime.py
jinja2/testsuite/inheritance.py

diff --git a/CHANGES b/CHANGES
index 87f705cb22876f7b1c3c6336856654be18de593b..b06192ca4d475ad63d65e7dd79f4dd219686c17d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,8 @@ Version 2.6
   integers instead of longs)
 - groupby filter now supports dotted notation for grouping by attributes
   of attributes.
+- scoped blocks not properly treat toplevel assignments and imports.
+  Previously an import suddenly "disappeared" in a scoped block.
 
 Version 2.5.5
 -------------
index 9bdeb011f918b625a78fbb400afa5ccfa6cac51d..72ab93e3b2d77b64d7f9bddeb621506825a65075 100644 (file)
@@ -190,6 +190,7 @@ class Context(object):
         """Internal helper function to create a derived context."""
         context = new_context(self.environment, self.name, {},
                               self.parent, True, None, locals)
+        context.vars.update(self.vars)
         context.eval_ctx = self.eval_ctx
         context.blocks.update((k, list(v)) for k, v in self.blocks.iteritems())
         return context
index 5db1cd61265cb51f987fc6e0d1e355aca3fd367f..355aa0c9b52f3ace022ac641b5d8e334bd3220d6 100644 (file)
@@ -159,6 +159,29 @@ class InheritanceTestCase(JinjaTestCase):
                             '{{ super() }}|{{ item * 2 }}{% endblock %}')
         assert t.render(seq=range(5)) == '[0|0][1|2][2|4][3|6][4|8]'
 
+    def test_scoped_block_after_inheritance(self):
+        env = Environment(loader=DictLoader({
+            'layout.html': '''
+            {% block useless %}{% endblock %}
+            ''',
+            'index.html': '''
+            {%- extends 'layout.html' %}
+            {% from 'helpers.html' import foo with context %}
+            {% block useless %}
+                {% for x in [1, 2, 3] %}
+                    {% block testing scoped %}
+                        {{ foo(x) }}
+                    {% endblock %}
+                {% endfor %}
+            {% endblock %}
+            ''',
+            'helpers.html': '''
+            {% macro foo(x) %}{{ the_foo + x }}{% endmacro %}
+            '''
+        }))
+        rv = env.get_template('index.html').render(the_foo=42).split()
+        assert rv == ['43', '44', '45']
+
 
 class BugFixTestCase(JinjaTestCase):