aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_features.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/test_features.py b/tests/test_features.py
index 25d58e4c..3187890e 100644
--- a/tests/test_features.py
+++ b/tests/test_features.py
@@ -1,7 +1,7 @@
import sys
import pytest
-from jinja2 import Template
+from jinja2 import Template, Environment, contextfilter
@pytest.mark.skipif(sys.version_info < (3, 5),
@@ -14,3 +14,27 @@ def test_generator_stop():
t = Template('a{{ bad.bar() }}b')
with pytest.raises(RuntimeError):
t.render(bad=X())
+
+
+@pytest.mark.skipif(sys.version_info[0] > 2,
+ reason='Feature only supported on 2.x')
+def test_ascii_str():
+ @contextfilter
+ def assert_func(context, value):
+ assert type(value) is context['expected_type']
+
+ env = Environment()
+ env.filters['assert'] = assert_func
+
+ env.policies['compiler.ascii_str'] = False
+ t = env.from_string('{{ "foo"|assert }}')
+ t.render(expected_type=unicode)
+
+ env.policies['compiler.ascii_str'] = True
+ t = env.from_string('{{ "foo"|assert }}')
+ t.render(expected_type=str)
+
+ for val in True, False:
+ env.policies['compiler.ascii_str'] = val
+ t = env.from_string(u'{{ "\N{SNOWMAN}"|assert }}')
+ t.render(expected_type=unicode)