Exemple #1
0
 def test_stopiteration_is_undefined(self):
     def test():
         raise StopIteration()
     t = Template('A{{ test() }}B')
     assert t.render(test=test) == 'AB'
     t = Template('A{{ test().missingattribute }}B')
     self.assert_raises(UndefinedError, t.render, test=test)
Exemple #2
0
    def test_call_with_args(self):
        t = Template("""{% macro dump_users(users) -%}
        <ul>
          {%- for user in users -%}
            <li><p>{{ user.username|e }}</p>{{ caller(user) }}</li>
          {%- endfor -%}
          </ul>
        {%- endmacro -%}

        {% call(user) dump_users(list_of_user) -%}
          <dl>
            <dl>Realname</dl>
            <dd>{{ user.realname|e }}</dd>
            <dl>Description</dl>
            <dd>{{ user.description }}</dd>
          </dl>
        {% endcall %}""")

        assert [
            x.strip() for x in t.render(list_of_user=[{
                'username': '******',
                'realname': 'something else',
                'description': 'test'
            }]).splitlines()
        ] == [
            u'<ul><li><p>apo</p><dl>', u'<dl>Realname</dl>',
            u'<dd>something else</dd>', u'<dl>Description</dl>',
            u'<dd>test</dd>', u'</dl>', u'</li></ul>'
        ]
    def test_call_with_args(self):
        t = Template("""{% macro dump_users(users) -%}
        <ul>
          {%- for user in users -%}
            <li><p>{{ user.username|e }}</p>{{ caller(user) }}</li>
          {%- endfor -%}
          </ul>
        {%- endmacro -%}

        {% call(user) dump_users(list_of_user) -%}
          <dl>
            <dl>Realname</dl>
            <dd>{{ user.realname|e }}</dd>
            <dl>Description</dl>
            <dd>{{ user.description }}</dd>
          </dl>
        {% endcall %}""")

        assert [x.strip() for x in t.render(list_of_user=[{
            'username':'******',
            'realname':'something else',
            'description':'test'
        }]).splitlines()] == [
            u'<ul><li><p>apo</p><dl>',
            u'<dl>Realname</dl>',
            u'<dd>something else</dd>',
            u'<dl>Description</dl>',
            u'<dd>test</dd>',
            u'</dl>',
            u'</li></ul>'
        ]
Exemple #4
0
 def test_stacked_locals_scoping_bug_twoframe(self):
     t = Template('''
         {% set x = 1 %}
         {% for item in foo %}
             {% if item == 1 %}
                 {% set x = 2 %}
             {% endif %}
         {% endfor %}
         {{ x }}
     ''')
     rv = t.render(foo=[1]).strip()
     assert rv == u'1'
 def test_stacked_locals_scoping_bug_twoframe(self):
     t = Template('''
         {% set x = 1 %}
         {% for item in foo %}
             {% if item == 1 %}
                 {% set x = 2 %}
             {% endif %}
         {% endfor %}
         {{ x }}
     ''')
     rv = t.render(foo=[1]).strip()
     assert rv == u'1'