From: Amy Date: Fri, 19 Jun 2020 15:53:29 +0000 (-0400) Subject: add more tests for import context behavior X-Git-Tag: 3.0.0rc1~87^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd88dec8ea7c5aa13fdf120481cc989be2c7916f;p=thirdparty%2Fjinja.git add more tests for import context behavior --- diff --git a/tests/test_imports.py b/tests/test_imports.py index 7a2bd942..bb7400f8 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -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):