env = Environment('{%', '%}', '${', '}')
tmpl = env.from_string('''{% for item in seq
%}${{'foo': item}|upper}{% endfor %}''')
- assert tmpl.render(seq=range(3)) == "{'FOO': 0}{'FOO': 1}{'FOO': 2}"
+ assert tmpl.render(seq=list(range(3))) == "{'FOO': 0}{'FOO': 1}{'FOO': 2}"
def test_comments(self):
env = Environment('<!--', '-->', '{', '}')
<li>{item}</li>
<!--- endfor -->
</ul>''')
- assert tmpl.render(seq=range(3)) == ("<ul>\n <li>0</li>\n "
+ assert tmpl.render(seq=list(range(3))) == ("<ul>\n <li>0</li>\n "
"<li>1</li>\n <li>2</li>\n</ul>")
def test_string_escapes(self):
- for char in u'\0', u'\u2668', u'\xe4', u'\t', u'\r', u'\n':
+ for char in '\0', '\u2668', '\xe4', '\t', '\r', '\n':
tmpl = env.from_string('{{ %s }}' % jinja_string_repr(char))
assert tmpl.render() == char
- assert env.from_string('{{ "\N{HOT SPRINGS}" }}').render() == u'\u2668'
+ assert env.from_string('{{ "\N{HOT SPRINGS}" }}').render() == '\u2668'
def test_bytefallback(self):
from pprint import pformat
- tmpl = env.from_string(u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}''')
- assert tmpl.render() == pformat('foo') + '|' + pformat(u'bär')
+ tmpl = env.from_string('''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}''')
+ assert tmpl.render() == pformat('foo') + '|' + pformat('bär')
def test_operators(self):
from jinja2.lexer import operators
- for test, expect in operators.iteritems():
+ for test, expect in operators.items():
if test in '([{}])':
continue
stream = env.lexer.tokenize('{{ %s }}' % test)
- stream.next()
+ next(stream)
assert stream.current.type == expect
def test_normalizing(self):
<? for item in seq -?>
<?= item ?>
<?- endfor ?>''')
- assert tmpl.render(seq=range(5)) == '01234'
+ assert tmpl.render(seq=list(range(5))) == '01234'
def test_erb_syntax(self):
env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')
<% for item in seq -%>
<%= item %>
<%- endfor %>''')
- assert tmpl.render(seq=range(5)) == '01234'
+ assert tmpl.render(seq=list(range(5))) == '01234'
def test_comment_syntax(self):
env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')
<!-- for item in seq --->
${item}
<!--- endfor -->''')
- assert tmpl.render(seq=range(5)) == '01234'
+ assert tmpl.render(seq=list(range(5))) == '01234'
def test_balancing(self):
tmpl = env.from_string('''{{{'foo':'bar'}.foo}}''')
% for item in seq:
${item}
% endfor''')
- assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \
- range(5)
+ assert [int(x.strip()) for x in tmpl.render(seq=list(range(5))).split()] == \
+ list(range(5))
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')
tmpl = env.from_string('''\
% for item in seq:
${item} ## the rest of the stuff
% endfor''')
- assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \
- range(5)
+ assert [int(x.strip()) for x in tmpl.render(seq=list(range(5))).split()] == \
+ list(range(5))
def test_line_syntax_priority(self):
# XXX: why is the whitespace there in front of the newline?
def assert_error(code, expected):
try:
Template(code)
- except TemplateSyntaxError, e:
+ except TemplateSyntaxError as e:
assert str(e) == expected, 'unexpected error message'
else:
assert False, 'that was supposed to be an error'
assert tmpl.render() == 'foobarbaz'
def test_notin(self):
- bar = xrange(100)
+ bar = range(100)
tmpl = env.from_string('''{{ not 42 in bar }}''')
- assert tmpl.render(bar=bar) == unicode(not 42 in bar)
+ assert tmpl.render(bar=bar) == str(not 42 in bar)
def test_implicit_subscribed_tuple(self):
class Foo(object):
def __getitem__(self, x):
return x
t = env.from_string('{{ foo[1, 2] }}')
- assert t.render(foo=Foo()) == u'(1, 2)'
+ assert t.render(foo=Foo()) == '(1, 2)'
def test_raw2(self):
tmpl = env.from_string('{% raw %}{{ FOO }} and {% BAR %}{% endraw %}')