Fixed python_path problem.
[smonitor.git] / lib / jinja2 / testsuite / debug.py
blob7552dec38932657f126c844fce56ccd263ff1a82
1 # -*- coding: utf-8 -*-
2 """
3 jinja2.testsuite.debug
4 ~~~~~~~~~~~~~~~~~~~~~~
6 Tests the debug system.
8 :copyright: (c) 2010 by the Jinja Team.
9 :license: BSD, see LICENSE for more details.
10 """
11 import sys
12 import unittest
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):
25 def test():
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>)
30 \{\{ fail\(\) \}\}
31 File ".*?debug.pyc?", line \d+, in <lambda>
32 tmpl\.render\(fail=lambda: 1 / 0\)
33 ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero
34 ''')
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
40 # be fixed though.
41 self.assert_traceback_matches(lambda: env.get_template('syntaxerror.html'), r'''(?sm)
42 File ".*?syntaxerror.html", line 4, in (template|<module>)
43 \{% endif %\}.*?
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'.
45 ''')
47 def test_regular_syntax_error(self):
48 def test():
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
54 line 42''')
57 def suite():
58 suite = unittest.TestSuite()
59 suite.addTest(unittest.makeSuite(DebugTestCase))
60 return suite