Skip to content
Myr

test_old_bugs.py

This file

Path

tests/test_old_bugs.py

62 lines · 1.7 KiB · Python

Last changed by

Added testcase for #335Armin Ronacherbefore adoption1dcafe5

History of this file

Take it

1# -*- coding: utf-8 -*-2"""3    Tests for old bugs4    ~~~~~~~~~~~~~~~~~~56    Unittest that test situations caused by various older bugs.78    :copyright: (c) 2009 by the Jinja Team.9    :license: BSD.10"""11from py.test import raises12from jinja2 import Environment, DictLoader, TemplateSyntaxError131415def test_keyword_folding():16    env = Environment()17    env.filters['testing'] = lambda value, some: value + some18    assert env.from_string("{{ 'test'|testing(some='stuff') }}") \19           .render() == 'teststuff'202122def test_extends_output_bugs():23    env = Environment(loader=DictLoader({24        'parent.html': '(({% block title %}{% endblock %}))'25    }))2627    t = env.from_string('{% if expr %}{% extends "parent.html" %}{% endif %}'28                        '[[{% block title %}title{% endblock %}]]'29                        '{% for item in [1, 2, 3] %}({{ item }}){% endfor %}')30    assert t.render(expr=False) == '[[title]](1)(2)(3)'31    assert t.render(expr=True) == '((title))'323334def test_urlize_filter_escaping(env):35    tmpl = env.from_string('{{ "http://www.example.org/<foo"|urlize }}')36    assert tmpl.render() == '<a href="http://www.example.org/&lt;foo">http://www.example.org/&lt;foo</a>'373839def test_loop_call_loop(env):40    tmpl = env.from_string('''4142    {% macro test() %}43        {{ caller() }}44    {% endmacro %}4546    {% for num1 in range(5) %}47        {% call test() %}48            {% for num2 in range(10) %}49                {{ loop.index }}50            {% endfor %}51        {% endcall %}52    {% endfor %}5354    ''')5556    assert tmpl.render() == ''575859def test_weird_inline_comment():60    env = Environment(line_statement_prefix='%')61    raises(TemplateSyntaxError, env.from_string,62           '% for item in seq {# missing #}\n...% endfor')