diff options
author | David Lord <davidism@gmail.com> | 2020-01-28 20:16:59 -0800 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2020-02-05 08:44:15 -0800 |
commit | 2a8515d2e53a2be475d9df3fe44e308501201a95 (patch) | |
tree | 88c9e788ce0e0be96b27e0e40f82e7c406567ee3 /tests/test_imports.py | |
parent | 42edc132902562e1e16f190bea60362865da894f (diff) | |
download | jinja-2a8515d2e53a2be475d9df3fe44e308501201a95.tar.gz |
apply pyupgrade and f-strings
Diffstat (limited to 'tests/test_imports.py')
-rw-r--r-- | tests/test_imports.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/test_imports.py b/tests/test_imports.py index 0dae2173..ca4de705 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -1,11 +1,11 @@ -# -*- coding: utf-8 -*- import pytest -from jinja2 import DictLoader -from jinja2 import Environment +from jinja2.environment import Environment from jinja2.exceptions import TemplateNotFound from jinja2.exceptions import TemplatesNotFound from jinja2.exceptions import TemplateSyntaxError +from jinja2.exceptions import UndefinedError +from jinja2.loaders import DictLoader @pytest.fixture @@ -24,7 +24,7 @@ def test_env(): @pytest.mark.imports -class TestImports(object): +class TestImports: def test_context_imports(self, test_env): t = test_env.from_string('{% import "module" as m %}{{ m.test() }}') assert t.render(foo=42) == "[|23]" @@ -93,10 +93,16 @@ class TestImports(object): assert m.variable == 42 assert not hasattr(m, "notthere") + def test_not_exported(self, test_env): + t = test_env.from_string("{% from 'module' import nothing %}{{ nothing() }}") + + with pytest.raises(UndefinedError, match="does not export the requested name"): + t.render() + @pytest.mark.imports @pytest.mark.includes -class TestIncludes(object): +class TestIncludes: def test_context_include(self, test_env): t = test_env.from_string('{% include "header" %}') assert t.render(foo=42) == "[42|23]" |