blob: d068e2699df6c23da95c6ec57719a2ed2a595f24 [file] [log] [blame]
Armin Ronacher1fb42692010-02-09 21:14:16 +01001# -*- coding: utf-8 -*-
2"""
3 jinja2.testsuite.debug
4 ~~~~~~~~~~~~~~~~~~~~~~
5
6 Tests the debug system.
7
8 :copyright: (c) 2010 by the Jinja Team.
9 :license: BSD, see LICENSE for more details.
10"""
11import unittest
12
13from jinja2.testsuite import JinjaTestCase, filesystem_loader
14
15from jinja2 import Environment, TemplateSyntaxError
16
17env = Environment(loader=filesystem_loader)
18
19
20class DebugTestCase(JinjaTestCase):
21
22 def test_runtime_error(self):
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 code
28 \{\{ fail\(\) \}\}
29 File ".*?debug.pyc?", line \d+, in <lambda>
30 tmpl\.render\(fail=lambda: 1 / 0\)
31ZeroDivisionError: integer division or modulo by zero
32''')
33
34 def test_syntax_error(self):
35 self.assert_traceback_matches(lambda: env.get_template('syntaxerror.html'), r'''
36 File ".*?syntaxerror.html", line 4, in template
37 \{% endif %\}
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'.
39 ''')
40
41 def test_regular_syntax_error(self):
42 def test():
43 raise TemplateSyntaxError('wtf', 42)
44 self.assert_traceback_matches(test, r'''
45 File ".*debug.pyc?", line \d+, in test
46 raise TemplateSyntaxError\('wtf', 42\)
47TemplateSyntaxError: wtf
48 line 42''')
49
50
51def suite():
52 suite = unittest.TestSuite()
53 suite.addTest(unittest.makeSuite(DebugTestCase))
54 return suite