Skip to content
Myr

test_undefined.py

This file

Path

tests/test_undefined.py

82 lines · 2.4 KiB · Python

Last changed by

Copyright switch to "The Jinja Team".Armin Ronacherbefore adoption62ccd1b

History of this file

Take it

The walk stopped after 200 commits: lines older than b217886 point at it.

added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886

lines 1–5why, one step back
1# -*- coding: utf-8 -*-
2"""3 unit test for the undefined types4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~5

Copyright switch to "The Jinja Team".Armin Ronacherbefore adoption62ccd1b

line 6why, one step back
6 :copyright: (c) 2009 by the Jinja Team.

added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886

lines 7–8why, one step back
7 :license: BSD, see LICENSE for more details.
8"""

Fixed a bug in the subscript operation.Armin Ronacherbefore adoption5c3c470

lines 9–11why, one step back
9from py.test import raises
10from jinja2 import Template11from jinja2.exceptions import UndefinedError

added author information and fixed small off-by-one bugArmin Ronacherbefore adoptionb217886

lines 12–77why, one step back
12
1314test_default_undefined = '''15>>> from jinja2 import Environment, Undefined16>>> env = Environment(undefined=Undefined)17>>> env.from_string('{{ missing }}').render()18u''19>>> env.from_string('{{ missing.attribute }}').render()20Traceback (most recent call last):21 ...22UndefinedError: 'missing' is undefined23>>> env.from_string('{{ missing|list }}').render()24u'[]'25>>> env.from_string('{{ missing is not defined }}').render()26u'True'27>>> env.from_string('{{ foo.missing }}').render(foo=42)28u''29>>> env.from_string('{{ not missing }}').render()30u'True'31'''3233test_debug_undefined = '''34>>> from jinja2 import Environment, DebugUndefined35>>> env = Environment(undefined=DebugUndefined)36>>> env.from_string('{{ missing }}').render()37u'{{ missing }}'38>>> env.from_string('{{ missing.attribute }}').render()39Traceback (most recent call last):40 ...41UndefinedError: 'missing' is undefined42>>> env.from_string('{{ missing|list }}').render()43u'[]'44>>> env.from_string('{{ missing is not defined }}').render()45u'True'46>>> env.from_string('{{ foo.missing }}').render(foo=42)47u"{{ no such element: int['missing'] }}"48>>> env.from_string('{{ not missing }}').render()49u'True'50'''5152test_strict_undefined = '''53>>> from jinja2 import Environment, StrictUndefined54>>> env = Environment(undefined=StrictUndefined)55>>> env.from_string('{{ missing }}').render()56Traceback (most recent call last):57 ...58UndefinedError: 'missing' is undefined59>>> env.from_string('{{ missing.attribute }}').render()60Traceback (most recent call last):61 ...62UndefinedError: 'missing' is undefined63>>> env.from_string('{{ missing|list }}').render()64Traceback (most recent call last):65 ...66UndefinedError: 'missing' is undefined67>>> env.from_string('{{ missing is not defined }}').render()68u'True'69>>> env.from_string('{{ foo.missing }}').render(foo=42)70Traceback (most recent call last):71 ...72UndefinedError: 'int' object has no attribute 'missing'73>>> env.from_string('{{ not missing }}').render()74Traceback (most recent call last):75 ...76UndefinedError: 'missing' is undefined77'''

Fixed a bug in the subscript operation.Armin Ronacherbefore adoption5c3c470

lines 78–82why, one step back
78
7980def test_indexing_gives_undefined():81 t = Template("{{ var[42].foo }}")82 raises(UndefinedError, t.render, var=0)