Exemple #1
0
def test_simple_repr():
    assert repr(parse("{{ x }}")) == textwrap.dedent("""
    {
        x: {{x}}
    }
    {% program None %} ==> []
        {{ x }} ===> ['x']
    {% endprogram %}""")
Exemple #2
0
def test_include5():
    assert repr(parse("""
    {% include "testdata/include2.html" %}
    """, os.path.join(BASEDIR, 'curdir'))) == textwrap.dedent("""
    {
        include2: {{include2}}
    }
    {% program None %} ==> []

    {% endprogram %}""")
Exemple #3
0
def test_include():
    assert (
        parse(
            """
    {% include "./testdata/a-template.html" %}
    """,
            os.path.join(BASEDIR, "curdir"),
        ).fvars()
        == {"a"}
    )
Exemple #4
0
def test_include3():
    assert (
        parse(
            """
    {% include "testdata/for-template.html" %}
    """,
            os.path.join(BASEDIR, "curdir"),
        ).fvars()
        == {"alist", "b", "c", "d", "e", "f"}
    )
Exemple #5
0
def test_include5():
    assert (
        parse(
            """
    {% include "testdata/include1.html" %}
    """,
            os.path.join(BASEDIR, "curdir"),
        ).fvars()
        == {"include1", "include2"}
    )
Exemple #6
0
def test_with2():
    assert (
        parse(
            """
    {% with foo.bar as x %}
        {{ x }} {{ y }}
    {% endwith %}
    """
        ).fvars()
        == {"foo", "y"}
    )
Exemple #7
0
def test_for():
    assert (
        parse(
            u"""
    {% for a in alist %}
        {{ a }} {{ b }}
    {% endfor %}
    """
        ).fvars()
        == {"alist", "b"}
    )
Exemple #8
0
def test_include2():
    assert (
        parse(
            """
    {% for a in alist %}
        {% include "testdata/a-template.html" %}
    {% endfor %}
    """,
            os.path.join(BASEDIR, "curdir"),
        ).fvars()
        == {"alist"}
    )
Exemple #9
0
def test_if():
    assert (
        parse(
            """
    {% if a %}
        {{ b }}
    {% elif c == d %}
        {{ e }}
    {% else %}
        {{ f }}
    {% endif %}
    """
        ).fvars()
        == set("abcdef")
    )
Exemple #10
0
def test_value():
    assert parse("{{ a }}").fvars() == {"a"}
Exemple #11
0
def test_load():
    assert parse("{% load foo %}").fvars() == set()