49c66bb1c91224c72c95cf532037c0b2c96b4060
[jinja2.git] / tests / test_debug.py
1 # -*- coding: utf-8 -*-
2 """
3     Test debug interface
4     ~~~~~~~~~~~~~~~~~~~~
5
6     Tests the traceback rewriter.
7
8     :copyright: (c) 2009 by the Jinja Team.
9     :license: BSD.
10 """
11 from jinja2 import Environment
12 from test_loaders import filesystem_loader
13
14 import conftest
15 if conftest.NOSE:
16     import sys
17     MODULE = sys.modules[__name__]
18
19
20 env = Environment(loader=filesystem_loader)
21
22
23 def test_runtime_error():
24     '''
25 >>> tmpl = MODULE.env.get_template('broken.html')
26 >>> tmpl.render(fail=lambda: 1 / 0)
27 Traceback (most recent call last):
28   File "loaderres/templates/broken.html", line 2, in top-level template code
29     {{ fail() }}
30   File "<doctest test_runtime_error[1]>", line 1, in <lambda>
31     tmpl.render(fail=lambda: 1 / 0)
32 ZeroDivisionError: integer division or modulo by zero
33 '''
34
35
36 def test_syntax_error():
37     '''
38 >>> tmpl = MODULE.env.get_template('syntaxerror.html')
39 Traceback (most recent call last):
40   ...
41 TemplateSyntaxError: unknown tag 'endif'
42   File "loaderres/templates\\syntaxerror.html", line 4
43     {% endif %}
44 '''
45
46
47 def test_regular_syntax_error():
48     '''
49 >>> from jinja2.exceptions import TemplateSyntaxError
50 >>> raise TemplateSyntaxError('wtf', 42)
51 Traceback (most recent call last):
52   ...
53   File "<doctest test_regular_syntax_error[1]>", line 1, in <module>
54     raise TemplateSyntaxError('wtf', 42)
55 TemplateSyntaxError: wtf
56   line 42
57 '''