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
def test_consume(): """Test that consume consumes an iterator.""" x = iter([1, 2, 3, 4, 5]) consume(x) with pytest.raises(StopIteration): next(x)