1 # -*- coding: utf-8 -*-
6 Tests the debug system.
8 :copyright: (c) 2010 by the Jinja Team.
9 :license: BSD, see LICENSE for more details.
14 from jinja2
.testsuite
import JinjaTestCase
, filesystem_loader
16 from jinja2
import Environment
, TemplateSyntaxError
18 env
= Environment(loader
=filesystem_loader
)
21 class DebugTestCase(JinjaTestCase
):
23 if sys
.version_info
[:2] != (2, 4):
24 def test_runtime_error(self
):
26 tmpl
.render(fail
=lambda: 1 / 0)
27 tmpl
= env
.get_template('broken.html')
28 self
.assert_traceback_matches(test
, r
'''
29 File ".*?broken.html", line 2, in (top-level template code|<module>)
31 File ".*?debug.pyc?", line \d+, in <lambda>
32 tmpl\.render\(fail=lambda: 1 / 0\)
33 ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero
36 def test_syntax_error(self
):
37 # XXX: the .*? is necessary for python3 which does not hide
38 # some of the stack frames we don't want to show. Not sure
39 # what's up with that, but that is not that critical. Should
41 self
.assert_traceback_matches(lambda: env
.get_template('syntaxerror.html'), r
'''(?sm)
42 File ".*?syntaxerror.html", line 4, in (template|<module>)
44 (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'.
47 def test_regular_syntax_error(self
):
49 raise TemplateSyntaxError('wtf', 42)
50 self
.assert_traceback_matches(test
, r
'''
51 File ".*debug.pyc?", line \d+, in test
52 raise TemplateSyntaxError\('wtf', 42\)
53 (jinja2\.exceptions\.)?TemplateSyntaxError: wtf
58 suite
= unittest
.TestSuite()
59 suite
.addTest(unittest
.makeSuite(DebugTestCase
))