blob: 49c66bb1c91224c72c95cf532037c0b2c96b4060 [file] [log] [blame]
Armin Ronacher5411ce72008-05-25 11:36:22 +02001# -*- coding: utf-8 -*-
2"""
3 Test debug interface
4 ~~~~~~~~~~~~~~~~~~~~
5
6 Tests the traceback rewriter.
7
Armin Ronacher62ccd1b2009-01-04 14:26:19 +01008 :copyright: (c) 2009 by the Jinja Team.
Armin Ronacher5411ce72008-05-25 11:36:22 +02009 :license: BSD.
10"""
11from jinja2 import Environment
12from test_loaders import filesystem_loader
13
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020014import conftest
15if conftest.NOSE:
16 import sys
17 MODULE = sys.modules[__name__]
18
Armin Ronacher5411ce72008-05-25 11:36:22 +020019
20env = Environment(loader=filesystem_loader)
21
22
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020023def test_runtime_error():
24 '''
Armin Ronacher5411ce72008-05-25 11:36:22 +020025>>> tmpl = MODULE.env.get_template('broken.html')
26>>> tmpl.render(fail=lambda: 1 / 0)
27Traceback (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)
32ZeroDivisionError: integer division or modulo by zero
33'''
34
35
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020036def test_syntax_error():
37 '''
Armin Ronacher5411ce72008-05-25 11:36:22 +020038>>> tmpl = MODULE.env.get_template('syntaxerror.html')
39Traceback (most recent call last):
40 ...
Armin Ronacherd416a972009-02-24 22:58:00 +010041TemplateSyntaxError: unknown tag 'endif'
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020042 File "loaderres/templates\\syntaxerror.html", line 4
43 {% endif %}
Armin Ronacherd416a972009-02-24 22:58:00 +010044'''
45
46
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020047def test_regular_syntax_error():
48 '''
Armin Ronacherd416a972009-02-24 22:58:00 +010049>>> from jinja2.exceptions import TemplateSyntaxError
50>>> raise TemplateSyntaxError('wtf', 42)
51Traceback (most recent call last):
52 ...
53 File "<doctest test_regular_syntax_error[1]>", line 1, in <module>
54 raise TemplateSyntaxError('wtf', 42)
55TemplateSyntaxError: wtf
56 line 42
Armin Ronacher5411ce72008-05-25 11:36:22 +020057'''