blob: d8e8a44060562483d895e3d093b47395a1e1a171 [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
Armin Ronacher5411ce72008-05-25 11:36:22 +020014env = Environment(loader=filesystem_loader)
15
16
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020017def test_runtime_error():
18 '''
Armin Ronacher42979eb2009-07-26 11:08:50 +020019>>> tmpl = env.get_template('broken.html')
Armin Ronacher5411ce72008-05-25 11:36:22 +020020>>> tmpl.render(fail=lambda: 1 / 0)
21Traceback (most recent call last):
22 File "loaderres/templates/broken.html", line 2, in top-level template code
23 {{ fail() }}
24 File "<doctest test_runtime_error[1]>", line 1, in <lambda>
25 tmpl.render(fail=lambda: 1 / 0)
26ZeroDivisionError: integer division or modulo by zero
27'''
28
29
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020030def test_syntax_error():
31 '''
Armin Ronacher42979eb2009-07-26 11:08:50 +020032>>> tmpl = env.get_template('syntaxerror.html')
Armin Ronacher5411ce72008-05-25 11:36:22 +020033Traceback (most recent call last):
34 ...
Armin Ronacherd416a972009-02-24 22:58:00 +010035TemplateSyntaxError: unknown tag 'endif'
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020036 File "loaderres/templates\\syntaxerror.html", line 4
37 {% endif %}
Armin Ronacherd416a972009-02-24 22:58:00 +010038'''
39
40
Rene Leonhardtc7e6c6d2009-04-20 23:08:53 +020041def test_regular_syntax_error():
42 '''
Armin Ronacherd416a972009-02-24 22:58:00 +010043>>> from jinja2.exceptions import TemplateSyntaxError
44>>> raise TemplateSyntaxError('wtf', 42)
45Traceback (most recent call last):
46 ...
47 File "<doctest test_regular_syntax_error[1]>", line 1, in <module>
48 raise TemplateSyntaxError('wtf', 42)
49TemplateSyntaxError: wtf
50 line 42
Armin Ronacher5411ce72008-05-25 11:36:22 +020051'''