Ejemplo n.º 1
0
 def __call__(self, *args, **kwargs):
     context = self._template.new_context(dict(*args, **kwargs))
     consume(self._template.root_render_func(context))
     rv = context.vars['result']
     if self._undefined_to_none and isinstance(rv, Undefined):
         rv = None
     return rv
Ejemplo n.º 2
0
 def __call__(self, *args, **kwargs):
     context = self._template.new_context(dict(*args, **kwargs))
     consume(self._template.root_render_func(context))
     rv = context.vars['result']
     if self._undefined_to_none and isinstance(rv, Undefined):
         rv = None
     return rv
Ejemplo n.º 3
0
def test_consume():
    """Test that consume consumes an iterator."""
    x = iter([1, 2, 3, 4, 5])
    consume(x)
    with pytest.raises(StopIteration):
        next(x)