diff options
author | floatdrop <floatdrop@yandex-team.ru> | 2022-02-10 16:47:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:15 +0300 |
commit | e63b84f1d39557d9e46ac380b1f388271894293c (patch) | |
tree | 338cdaff3fb027e030b847db66df06019a0e3149 /contrib/python/Jinja2/py3/tests/test_inheritance.py | |
parent | f60febb7ea449535e7b073c386c7ff0539637fc0 (diff) | |
download | ydb-e63b84f1d39557d9e46ac380b1f388271894293c.tar.gz |
Restoring authorship annotation for <floatdrop@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/Jinja2/py3/tests/test_inheritance.py')
-rw-r--r-- | contrib/python/Jinja2/py3/tests/test_inheritance.py | 226 |
1 files changed, 113 insertions, 113 deletions
diff --git a/contrib/python/Jinja2/py3/tests/test_inheritance.py b/contrib/python/Jinja2/py3/tests/test_inheritance.py index 0c20d4da7d..1b2a5c217f 100644 --- a/contrib/python/Jinja2/py3/tests/test_inheritance.py +++ b/contrib/python/Jinja2/py3/tests/test_inheritance.py @@ -1,63 +1,63 @@ -import pytest - +import pytest + from jinja2 import DictLoader from jinja2 import Environment from jinja2 import TemplateRuntimeError from jinja2 import TemplateSyntaxError - + LAYOUTTEMPLATE = """\ -|{% block block1 %}block 1 from layout{% endblock %} -|{% block block2 %}block 2 from layout{% endblock %} -|{% block block3 %} -{% block block4 %}nested block 4 from layout{% endblock %} +|{% block block1 %}block 1 from layout{% endblock %} +|{% block block2 %}block 2 from layout{% endblock %} +|{% block block3 %} +{% block block4 %}nested block 4 from layout{% endblock %} {% endblock %}|""" - + LEVEL1TEMPLATE = """\ -{% extends "layout" %} +{% extends "layout" %} {% block block1 %}block 1 from level1{% endblock %}""" - + LEVEL2TEMPLATE = """\ -{% extends "level1" %} -{% block block2 %}{% block block5 %}nested block 5 from level2{% +{% extends "level1" %} +{% block block2 %}{% block block5 %}nested block 5 from level2{% endblock %}{% endblock %}""" - + LEVEL3TEMPLATE = """\ -{% extends "level2" %} -{% block block5 %}block 5 from level3{% endblock %} -{% block block4 %}block 4 from level3{% endblock %} +{% extends "level2" %} +{% block block5 %}block 5 from level3{% endblock %} +{% block block4 %}block 4 from level3{% endblock %} """ - + LEVEL4TEMPLATE = """\ -{% extends "level3" %} -{% block block3 %}block 3 from level4{% endblock %} +{% extends "level3" %} +{% block block3 %}block 3 from level4{% endblock %} """ - + WORKINGTEMPLATE = """\ -{% extends "layout" %} -{% block block1 %} - {% if false %} - {% block block2 %} +{% extends "layout" %} +{% block block1 %} + {% if false %} + {% block block2 %} this should work - {% endblock %} - {% endif %} -{% endblock %} + {% endblock %} + {% endif %} +{% endblock %} """ - + DOUBLEEXTENDS = """\ -{% extends "layout" %} -{% extends "layout" %} -{% block block1 %} - {% if false %} - {% block block2 %} +{% extends "layout" %} +{% extends "layout" %} +{% block block1 %} + {% if false %} + {% block block2 %} this should work - {% endblock %} - {% endif %} -{% endblock %} + {% endblock %} + {% endif %} +{% endblock %} """ - - -@pytest.fixture -def env(): + + +@pytest.fixture +def env(): return Environment( loader=DictLoader( { @@ -72,41 +72,41 @@ def env(): ), trim_blocks=True, ) - - + + class TestInheritance: - def test_layout(self, env): + def test_layout(self, env): tmpl = env.get_template("layout") assert tmpl.render() == ( "|block 1 from layout|block 2 from layout|nested block 4 from layout|" ) - - def test_level1(self, env): + + def test_level1(self, env): tmpl = env.get_template("level1") assert tmpl.render() == ( "|block 1 from level1|block 2 from layout|nested block 4 from layout|" ) - - def test_level2(self, env): + + def test_level2(self, env): tmpl = env.get_template("level2") assert tmpl.render() == ( "|block 1 from level1|nested block 5 from " "level2|nested block 4 from layout|" ) - - def test_level3(self, env): + + def test_level3(self, env): tmpl = env.get_template("level3") assert tmpl.render() == ( "|block 1 from level1|block 5 from level3|block 4 from level3|" ) - - def test_level4(self, env): + + def test_level4(self, env): tmpl = env.get_template("level4") assert tmpl.render() == ( "|block 1 from level1|block 5 from level3|block 3 from level4|" ) - - def test_super(self, env): + + def test_super(self, env): env = Environment( loader=DictLoader( { @@ -122,17 +122,17 @@ class TestInheritance: ) tmpl = env.get_template("c") assert tmpl.render() == "--INTRO--|BEFORE|[(INNER)]|AFTER" - - def test_working(self, env): + + def test_working(self, env): env.get_template("working") - - def test_reuse_blocks(self, env): + + def test_reuse_blocks(self, env): tmpl = env.from_string( "{{ self.foo() }}|{% block foo %}42{% endblock %}|{{ self.foo() }}" ) assert tmpl.render() == "42|42|42" - - def test_preserve_blocks(self, env): + + def test_preserve_blocks(self, env): env = Environment( loader=DictLoader( { @@ -144,8 +144,8 @@ class TestInheritance: ) tmpl = env.get_template("b") assert tmpl.render() == "BA" - - def test_dynamic_inheritance(self, env): + + def test_dynamic_inheritance(self, env): env = Environment( loader=DictLoader( { @@ -156,10 +156,10 @@ class TestInheritance: ) ) tmpl = env.get_template("child") - for m in range(1, 3): + for m in range(1, 3): assert tmpl.render(default=f"default{m}") == f"DEFAULT{m}CHILD" - - def test_multi_inheritance(self, env): + + def test_multi_inheritance(self, env): env = Environment( loader=DictLoader( { @@ -177,8 +177,8 @@ class TestInheritance: assert tmpl.render(default="default2") == "DEFAULT2CHILD" assert tmpl.render(default="default1") == "DEFAULT1CHILD" assert tmpl.render() == "DEFAULT1CHILD" - - def test_scoped_block(self, env): + + def test_scoped_block(self, env): env = Environment( loader=DictLoader( { @@ -191,8 +191,8 @@ class TestInheritance: "{% extends 'default.html' %}{% block item %}{{ item }}{% endblock %}" ) assert t.render(seq=list(range(5))) == "[0][1][2][3][4]" - - def test_super_in_scoped_block(self, env): + + def test_super_in_scoped_block(self, env): env = Environment( loader=DictLoader( { @@ -206,34 +206,34 @@ class TestInheritance: "{{ super() }}|{{ item * 2 }}{% endblock %}" ) assert t.render(seq=list(range(5))) == "[0|0][1|2][2|4][3|6][4|8]" - - def test_scoped_block_after_inheritance(self, env): + + def test_scoped_block_after_inheritance(self, env): env = Environment( loader=DictLoader( { "layout.html": """ - {% block useless %}{% endblock %} + {% block useless %}{% endblock %} """, "index.html": """ - {%- extends 'layout.html' %} - {% from 'helpers.html' import foo with context %} - {% block useless %} - {% for x in [1, 2, 3] %} - {% block testing scoped %} - {{ foo(x) }} - {% endblock %} - {% endfor %} - {% endblock %} + {%- extends 'layout.html' %} + {% from 'helpers.html' import foo with context %} + {% block useless %} + {% for x in [1, 2, 3] %} + {% block testing scoped %} + {{ foo(x) }} + {% endblock %} + {% endfor %} + {% endblock %} """, "helpers.html": """ - {% macro foo(x) %}{{ the_foo + x }}{% endmacro %} + {% macro foo(x) %}{{ the_foo + x }}{% endmacro %} """, } ) ) rv = env.get_template("index.html").render(the_foo=42).split() assert rv == ["43", "44", "45"] - + def test_level1_required(self, env): env = Environment( loader=DictLoader( @@ -245,7 +245,7 @@ class TestInheritance: ) rv = env.get_template("level1").render() assert rv == "[1]" - + def test_level2_required(self, env): env = Environment( loader=DictLoader( @@ -353,40 +353,40 @@ class TestInheritance: class TestBugFix: - def test_fixed_macro_scoping_bug(self, env): + def test_fixed_macro_scoping_bug(self, env): assert ( Environment( loader=DictLoader( { "test.html": """\ - {% extends 'details.html' %} - - {% macro my_macro() %} - my_macro - {% endmacro %} - - {% block inner_box %} - {{ my_macro() }} - {% endblock %} + {% extends 'details.html' %} + + {% macro my_macro() %} + my_macro + {% endmacro %} + + {% block inner_box %} + {{ my_macro() }} + {% endblock %} """, "details.html": """\ - {% extends 'standard.html' %} - - {% macro my_macro() %} - my_macro - {% endmacro %} - - {% block content %} - {% block outer_box %} - outer_box - {% block inner_box %} - inner_box - {% endblock %} - {% endblock %} - {% endblock %} + {% extends 'standard.html' %} + + {% macro my_macro() %} + my_macro + {% endmacro %} + + {% block content %} + {% block outer_box %} + outer_box + {% block inner_box %} + inner_box + {% endblock %} + {% endblock %} + {% endblock %} """, "standard.html": """ - {% block content %} {% endblock %} + {% block content %} {% endblock %} """, } ) @@ -396,10 +396,10 @@ class TestBugFix: .split() == ["outer_box", "my_macro"] ) - - def test_double_extends(self, env): - """Ensures that a template with more than 1 {% extends ... %} usage - raises a ``TemplateError``. - """ + + def test_double_extends(self, env): + """Ensures that a template with more than 1 {% extends ... %} usage + raises a ``TemplateError``. + """ with pytest.raises(TemplateRuntimeError, match="extended multiple times"): env.get_template("doublee").render() |