Esempio n. 1
0
    def test_complex(self):
        tpl = """Hello World

        {% for i in abc%}
          x {{i}}
        {% endfor %}

        That's all!"""
        t = Template(tpl)
        t.render(abc="123")
Esempio n. 2
0
 def test_context_inheritance(self):
     base = Template("HEAD {% for i in '123' %}"
                     "{%slot%}xxx{%endslot%}"
                     "{%endfor%} FOOTER")
     final = Template("body {{i}}", parent=base)
     res = final.render()
     assert res == "HEAD body 1body 2body 3 FOOTER"
Esempio n. 3
0
 def test_2levels(self):
     base = Template("HEAD {%slot%}xxx{%endslot%} FOOTER")
     first = Template("This is the body {% slot %} yyy {% endslot %}",
                      parent=base)
     second = Template("The end...", parent=first)
     res = second.render()
     assert res == "HEAD This is the body The end... FOOTER"
Esempio n. 4
0
 def test_loop(self):
     tpl = Template("{% for i in seq%}"
                    "{%if loop.first%}{{i}} is first{%endif%}"
                    "{%if loop.last%}{{i}} is last{%endif%}"
                    "{{i}}{{loop.index}}-{{loop.index0}}"
                    "{%endfor%}")
     res = tpl.render(seq="abcde")
     assert res == "a is firsta0-1b1-2c2-3d3-4e is laste4-5"
Esempio n. 5
0
 def test_explicit3(self):
     base = Template("HEAD {%slot main%}xxx{%endslot%} FOOTER")
     final = Template(
         "{%fill main%}This is the body{%endfill%}"
         "{%fill other%}Other fill{%endfill%}",
         parent=base)
     res = final.render()
     assert res == "HEAD This is the body FOOTER"
Esempio n. 6
0
 def test_multi_fill_sideeffect(self):
     """ if the child does not explicitly define a fill, it will be
         used for any / all slots """
     base = Template("HEAD {%slot main%}xxx{%endslot%} - "
                     "{% slot bar %}yyy{%endslot%} FOOTER")
     final = Template("Hello", parent=base)
     res = final.render()
     assert res == "HEAD Hello - Hello FOOTER"
Esempio n. 7
0
 def test_multi_fill(self):
     base = Template("HEAD {%slot main%}xxx{%endslot%} - "
                     "{% slot bar %}yyy{%endslot%} FOOTER")
     final = Template(
         "Hello "
         "{%fill main %}This is the main block"
         "{% endfill %} and "
         "{%fill bar %}this is the bar block"
         "{%endfill %}",
         parent=base)
     res = final.render()
     assert res == "HEAD This is the main block - this is the bar block FOOTER"
Esempio n. 8
0
    def test_total_madness1(self):
        base = Template("HEAD {%slot a%} aa {% endslot %}"
                        "{%for i in '123'%}"
                        "{%slot b %}{%endslot%}"
                        "{%endfor%}"
                        "FOOTER")
        c1 = Template(
            "{%fill a%}A{%endfill%}"
            "noise"
            "{%fill b%}"
            "{{i}}{%slot c%}..{%endslot%}"
            "{%endfill%}",
            parent=base)
        c2 = Template("Default", parent=c1)

        res = c2.render()
        assert res == "HEAD A1Default2Default3DefaultFOOTER"
Esempio n. 9
0
    def test_attraction_marker2(self):
        base = Template("""
<html>
<style>
  p, th, td {
    font-family: 'Open Sans', sans-serif;
  }
</style>
<body>
  {% slot content %}{% endslot %}
</body>

</html>
""")
        final = Template("<<MARKER>>", parent=base)
        res = final.render()
        assert '<<MARKER>>' in res
Esempio n. 10
0
 def test_string_expression_special2(self):
     tpl = Template("{{'{%hello%}'}}")
     assert tpl.render() == '{%hello%}'
Esempio n. 11
0
 def test_string_expression(self):
     tpl = Template("{{'hello'}}")
     assert tpl.render() == 'hello'
Esempio n. 12
0
 def test_expression(self):
     tpl = Template("{{i + j}}")
     assert tpl.render(i=10, j=5) == "15"
     assert tpl.render(i="Hello", j="World") == "HelloWorld"
Esempio n. 13
0
 def test_interpolation(self):
     tpl = Template("{{i}}")
     assert tpl.render(i=10) == "10"
     assert tpl.render(i=0) == "0"
     assert tpl.render(i=-10) == "-10"
     assert tpl.render(i="hello") == "hello"
Esempio n. 14
0
 def test_nondefault(self):
     base = Template("HEAD {%slot foo%}xxx{%endslot%} FOOTER")
     final = Template("{%fill foo%}This is the body{%endfill%}",
                      parent=base)
     res = final.render()
     assert res == "HEAD This is the body FOOTER"
Esempio n. 15
0
 def test_context_stacking(self):
     """ this is more of a context feature """
     tpl = Template("{%for i in j%}{{i}}{%endfor%}{{i}}")
     assert tpl.render(i="z", j=["a"]) == "az"
Esempio n. 16
0
 def test_simple(self):
     tpl = Template("{%for i in j%}{{i}}{% endfor %}")
     assert tpl.render(j="a") == "a"
     assert tpl.render(j=[1, 2, 3]) == "123"
Esempio n. 17
0
 def test_missing(self):
     base = Template("HEAD {%slot foo%}xxx{%endslot%} FOOTER")
     final = Template("{%fill main%}This is the body{%endfill%}",
                      parent=base)
     res = final.render()
     assert res == "HEAD xxx FOOTER"
Esempio n. 18
0
 def test_else(self):
     tpl = Template("{%if bool%}TRUE{%else%}FALSE{%endif%}")
     assert tpl.render(bool=True) == "TRUE"
     assert tpl.render(bool=False) == "FALSE"
Esempio n. 19
0
 def test_simple(self):
     base = Template("HEAD {%slot%}xxx{%endslot%} FOOTER")
     final = Template("This is the body", parent=base)
     res = final.render()
     assert res == "HEAD This is the body FOOTER"
Esempio n. 20
0
 def test_simple(self):
     tpl = Template("{%if bool%}TRUE{%endif%}")
     assert tpl.render(bool=True) == "TRUE"
     assert tpl.render(bool=False) == ""
Esempio n. 21
0
 def test_attraction_marker(self):
     base = Template("HEAD {% slot content %}xxx{% endslot %} FOOTER")
     final = Template("<<MARKER>>", parent=base)
     res = final.render()
     assert res == "HEAD <<MARKER>> FOOTER"