diff options
author | Amy <leiamy12@gmail.com> | 2020-06-19 11:53:29 -0400 |
---|---|---|
committer | Amy <leiamy12@gmail.com> | 2020-06-19 11:53:29 -0400 |
commit | cd88dec8ea7c5aa13fdf120481cc989be2c7916f (patch) | |
tree | da0ed2e790099ae193d797c44de07052d6632855 | |
parent | 5eea6e49e09971f844f7a3b6812c7be167ee04c9 (diff) | |
download | jinja-cd88dec8ea7c5aa13fdf120481cc989be2c7916f.tar.gz |
add more tests for import context behavior
-rw-r--r-- | tests/test_imports.py | 24 |
1 files changed, 24 insertions, 0 deletions
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): |