Skip to content
Myr

ALL TESTS PASS!

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 0d242be · Browse files · 4 files+29 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+29 added−12 removed

  • other:+29 added−12 removed

4 files+29 added−12 removed

modified:jinja2/testsuite/api.py+3 added-2 removed
27 unmodified lines
28 def test_item_and_attribute(self):29 from jinja2.sandbox import SandboxedEnvironment3031 for env in Environment(), SandboxedEnvironment():32 # the |list is necessary for python332 tmpl = env.from_string('{{ foo.items() }}')33 tmpl = env.from_string('{{ foo.items()|list }}')34 assert tmpl.render(foo={'items': 42}) == "[('items', 42)]"34 tmpl = env.from_string('{{ foo|attr("items")() }}')35 tmpl = env.from_string('{{ foo|attr("items")()|list }}')36 assert tmpl.render(foo={'items': 42}) == "[('items', 42)]"37 tmpl = env.from_string('{{ foo["items"] }}')38 assert tmpl.render(foo={'items': 42}) == '42'39
154 unmodified lines
modified:jinja2/testsuite/debug.py+11 added-6 removed
22 unmodified lines
23 def test():24 tmpl.render(fail=lambda: 1 / 0)25 tmpl = env.get_template('broken.html')26 self.assert_traceback_matches(test, r'''27 File ".*?broken.html", line 2, in top-level template code27 File ".*?broken.html", line 2, in (top-level template code|<module>)28 \{\{ fail\(\) \}\}29 File ".*?debug.pyc?", line \d+, in <lambda>30 tmpl\.render\(fail=lambda: 1 / 0\)31ZeroDivisionError: integer division or modulo by zero31ZeroDivisionError: int(eger)? division or modulo by zero32''')3334 def test_syntax_error(self):35 # XXX: the .*? is necessary for python3 which does not hide36 # some of the stack frames we don't want to show. Not sure37 # what's up with that, but that is not that critical. Should38 # be fixed though.35 self.assert_traceback_matches(lambda: env.get_template('syntaxerror.html'), r'''36 File ".*?syntaxerror.html", line 4, in template39 self.assert_traceback_matches(lambda: env.get_template('syntaxerror.html'), r'''(?sm)40 File ".*?syntaxerror.html", line 4, in (template|<module>)41 \{% endif %\}42 .*?38TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.43(jinja2\.exceptions\.)?TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.44 ''')4546 def test_regular_syntax_error(self):47 def test():48 raise TemplateSyntaxError('wtf', 42)49 self.assert_traceback_matches(test, r'''50 File ".*debug.pyc?", line \d+, in test51 raise TemplateSyntaxError\('wtf', 42\)47TemplateSyntaxError: wtf52(jinja2\.exceptions\.)?TemplateSyntaxError: wtf53 line 42''')545556def suite():
3 unmodified lines
modified:jinja2/testsuite/filters.py+3 added-2 removed
159 unmodified lines
160 '{{ [1, 2, 3]|reverse|list }}')161 assert tmpl.render() == 'raboof|[3, 2, 1]'162163 def test_string(self):164 x = [1, 2, 3, 4, 5]164 tmpl = env.from_string('''{{ range(10)|string }}''')165 assert tmpl.render(foo=range(10)) == unicode(xrange(10))165 tmpl = env.from_string('''{{ obj|string }}''')166 assert tmpl.render(obj=x) == unicode(x)167168 def test_title(self):169 tmpl = env.from_string('''{{ "foo bar"|title }}''')170 assert tmpl.render() == "Foo Bar"
111 unmodified lines
modified:jinja2/testsuite/lexnparse.py+12 added-2 removed
7 unmodified lines
8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import os12import sys13import time14import tempfile15import unittest16
3 unmodified lines
2021env = Environment()222324# how does a string look like in jinja syntax?25if sys.version_info < (3, 0):26 def jinja_string_repr(string):27 return repr(string)[1:]28else:29 jinja_string_repr = repr303132class LexerTestCase(JinjaTestCase):3334 def test_raw1(self):35 tmpl = env.from_string('{% raw %}foo{% endraw %}|'
18 unmodified lines
54 "<li>1</li>\n <li>2</li>\n</ul>")5556 def test_string_escapes(self):57 for char in u'\0', u'\u2668', u'\xe4', u'\t', u'\r', u'\n':49 tmpl = env.from_string('{{ %s }}' % repr(char)[1:])58 tmpl = env.from_string('{{ %s }}' % jinja_string_repr(char))59 assert tmpl.render() == char60 assert env.from_string('{{ "\N{HOT SPRINGS}" }}').render() == u'\u2668'6162 def test_bytefallback(self):63 from pprint import pformat64 tmpl = env.from_string(u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}''')55 assert tmpl.render() == u"'foo'|u'b\\xe4r'"65 assert tmpl.render() == pformat('foo') + '|' + pformat(u'bär')6667 def test_operators(self):68 from jinja2.lexer import operators69 for test, expect in operators.iteritems():
303 unmodified lines