test_features.py
This file
Path
tests/test_features.py
42 lines · 1.2 KiB · Python
Last changed by
Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
History of this fileTake it
1import sys23import pytest45from jinja2 import contextfilter6from jinja2 import Environment7from jinja2 import Template8from jinja2._compat import text_type91011@pytest.mark.skipif(sys.version_info < (3, 5), reason="Requires 3.5 or later")12def test_generator_stop():13 class X(object):14 def __getattr__(self, name):15 raise StopIteration()1617 t = Template("a{{ bad.bar() }}b")18 with pytest.raises(RuntimeError):19 t.render(bad=X())202122@pytest.mark.skipif(sys.version_info[0] > 2, reason="Feature only supported on 2.x")23def test_ascii_str():24 @contextfilter25 def assert_func(context, value):26 assert type(value) is context["expected_type"]2728 env = Environment()29 env.filters["assert"] = assert_func3031 env.policies["compiler.ascii_str"] = False32 t = env.from_string('{{ "foo"|assert }}')33 t.render(expected_type=text_type)3435 env.policies["compiler.ascii_str"] = True36 t = env.from_string('{{ "foo"|assert }}')37 t.render(expected_type=str)3839 for val in True, False:40 env.policies["compiler.ascii_str"] = val41 t = env.from_string(u'{{ "\N{SNOWMAN}"|assert }}')42 t.render(expected_type=text_type)