summaryrefslogtreecommitdiff
path: root/tests/test_imports.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_imports.py')
-rw-r--r--tests/test_imports.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/test_imports.py b/tests/test_imports.py
index a6d5161..4250eb9 100644
--- a/tests/test_imports.py
+++ b/tests/test_imports.py
@@ -11,7 +11,8 @@
import pytest
from jinja2 import Environment, DictLoader
-from jinja2.exceptions import TemplateNotFound, TemplatesNotFound
+from jinja2.exceptions import TemplateNotFound, TemplatesNotFound, \
+ TemplateSyntaxError
@pytest.fixture
@@ -50,7 +51,24 @@ class TestImports(object):
)
assert t.render(foo=42) == '[42|23]'
- def test_trailing_comma(self, test_env):
+ def test_import_needs_name(self, test_env):
+ test_env.from_string('{% from "foo" import bar %}')
+ test_env.from_string('{% from "foo" import bar, baz %}')
+
+ with pytest.raises(TemplateSyntaxError):
+ test_env.from_string('{% from "foo" import %}')
+
+ def test_no_trailing_comma(self, test_env):
+ with pytest.raises(TemplateSyntaxError):
+ test_env.from_string('{% from "foo" import bar, %}')
+
+ with pytest.raises(TemplateSyntaxError):
+ test_env.from_string('{% from "foo" import bar,, %}')
+
+ with pytest.raises(TemplateSyntaxError):
+ test_env.from_string('{% from "foo" import, %}')
+
+ def test_trailing_comma_with_context(self, test_env):
test_env.from_string('{% from "foo" import bar, baz with context %}')
test_env.from_string('{% from "foo" import bar, baz, with context %}')
test_env.from_string('{% from "foo" import bar, with context %}')