]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
add more tests for import context behavior
authorAmy <leiamy12@gmail.com>
Fri, 19 Jun 2020 15:53:29 +0000 (11:53 -0400)
committerAmy <leiamy12@gmail.com>
Fri, 19 Jun 2020 15:53:29 +0000 (11:53 -0400)
tests/test_imports.py

index 7a2bd9428d9990aa8feba1e8a1b887b51edeeefd..bb7400f864c662de88d1ede557792ab7d45768a4 100644 (file)
@@ -98,6 +98,30 @@ class TestImports:
         with pytest.raises(UndefinedError, match="does not export the requested name"):
             t.render()
 
+    def test_import_with_globals(self, test_env):
+        env = Environment(
+            loader=DictLoader(
+                {
+                    "macros": "{% macro testing() %}foo: {{ foo }}{% endmacro %}",
+                    "test": "{% import 'macros' as m %}{{ m.testing() }}",
+                }
+            )
+        )
+        tmpl = env.get_template("test", globals={"foo": "bar"})
+        assert tmpl.render() == "foo: bar"
+
+    def test_from_import_with_globals(self, test_env):
+        env = Environment(
+            loader=DictLoader(
+                {
+                    "macros": "{% macro testing() %}foo: {{ foo }}{% endmacro %}",
+                    "test": "{% from 'macros' import testing %}{{ testing() }}",
+                }
+            )
+        )
+        tmpl = env.get_template("test", globals={"foo": "bar"})
+        assert tmpl.render() == "foo: bar"
+
 
 class TestIncludes:
     def test_context_include(self, test_env):