aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Jinja2/py2/tests/test_features.py
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/Jinja2/py2/tests/test_features.py
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
Diffstat (limited to 'contrib/python/Jinja2/py2/tests/test_features.py')
-rw-r--r--contrib/python/Jinja2/py2/tests/test_features.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/contrib/python/Jinja2/py2/tests/test_features.py b/contrib/python/Jinja2/py2/tests/test_features.py
new file mode 100644
index 0000000000..34b6f200de
--- /dev/null
+++ b/contrib/python/Jinja2/py2/tests/test_features.py
@@ -0,0 +1,42 @@
+import sys
+
+import pytest
+
+from jinja2 import contextfilter
+from jinja2 import Environment
+from jinja2 import Template
+from jinja2._compat import text_type
+
+
+@pytest.mark.skipif(sys.version_info < (3, 5), reason="Requires 3.5 or later")
+def test_generator_stop():
+ class X(object):
+ def __getattr__(self, name):
+ raise StopIteration()
+
+ 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=text_type)
+
+ 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=text_type)