From a251596156fde3b3e79c3309e6b5681a98c29d3e Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Wed, 9 Oct 2024 22:37:21 +0800 Subject: [PATCH] feat: add a test case to ensure local vars are forwarded in context --- python/tests/test_template.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/tests/test_template.py b/python/tests/test_template.py index 5953435..571baea 100644 --- a/python/tests/test_template.py +++ b/python/tests/test_template.py @@ -377,6 +377,10 @@ def test_components_context(): assert Template("{% a b=1, c=2 %}").render({"a": Template("{{ b }}{{ c }}{{ d }}"), "d": 3}) == "123" +def test_components_in_for_loop(): + assert Template("{% for i in '123' %}{% a %}{% endfor %}").render({"a": Template("{{ i }}")}) == "123" + + def test_else_tag_in_for_loop(): render_assert("{% for i in '123' %}{{ i }}{% else %}4{% endfor %}", None, "1234") @@ -386,7 +390,11 @@ def test_elif_tag(): def test_while_loop(): - render_assert("{% while nums %}{{ nums.pop() }}{% else %}!{% endwhile %}", {"nums": [1, 2, 3]}, "321!") + render_assert( + "{% while nums %}{{ nums.pop() }}{% else %}!{% endwhile %}", + {"nums": [1, 2, 3]}, + "321!", + ) def test_custom_indent():