From be1dca1143abe7784be7c5ca4a626fd184670d8b Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 23 May 2008 23:43:45 +0200 Subject: [PATCH] added two more unittests for inheritance --HG-- branch : trunk --- tests/test_inheritance.py | 24 ++++++++++++++++++++++++ tests/test_lexer.py | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index ee8296a..8884b9f 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -107,3 +107,27 @@ def test_preserve_blocks(): })) tmpl = env.get_template('b') assert tmpl.render() == 'BA' + + +def test_dynamic_inheritance(): + env = Environment(loader=DictLoader({ + 'master1': 'MASTER1{% block x %}{% endblock %}', + 'master2': 'MASTER2{% block x %}{% endblock %}', + 'child': '{% extends master %}{% block x %}CHILD{% endblock %}' + })) + tmpl = env.get_template('child') + for m in range(1, 3): + assert tmpl.render(master='master%d' % m) == 'MASTER%dCHILD' % m + + +def test_multi_inheritance(): + env = Environment(loader=DictLoader({ + 'master1': 'MASTER1{% block x %}{% endblock %}', + 'master2': 'MASTER2{% block x %}{% endblock %}', + 'child': '''{% if master %}{% extends master %}{% else %}{% extends + 'master1' %}{% endif %}{% block x %}CHILD{% endblock %}''' + })) + tmpl = env.get_template('child') + assert tmpl.render(master='master2') == 'MASTER2CHILD' + assert tmpl.render(master='master1') == 'MASTER1CHILD' + assert tmpl.render() == 'MASTER1CHILD' diff --git a/tests/test_lexer.py b/tests/test_lexer.py index a6717e9..cb1e2dc 100644 --- a/tests/test_lexer.py +++ b/tests/test_lexer.py @@ -58,3 +58,12 @@ def test_operators(env): stream = env.lexer.tokenize('{{ %s }}' % test) stream.next() assert stream.current.type == expect + + +def test_normalizing(): + from jinja2 import Environment + for seq in '\r', '\r\n', '\n': + env = Environment(newline_sequence=seq) + tmpl = env.from_string('1\n2\r\n3\n4\n') + result = tmpl.render() + assert result.replace(seq, 'X') == '1X2X3X4' -- 2.26.2