Skip to content
This repository
Browse code

Removed old testsuite.

--HG--
branch : trunk
  • Loading branch information...
commit b36ddc9a97c3f17b8f728707f0e61ec6cb49d148 1 parent 9d8ff9e
Armin Ronacher authored February 09, 2010
6  Makefile
... ...
@@ -1,8 +1,4 @@
1 1
 test:
2  
-	nosetests --with-doctest jinja2 tests
3  
-
4  
-2to3:
5  
-	rm -rf build/lib
6  
-	python3 setup.py build
  2
+	python setup.py test
7 3
 
8 4
 .PHONY: test
0  tests/loaderres/__init__.py
No changes.
3  tests/loaderres/templates/broken.html
... ...
@@ -1,3 +0,0 @@
1  
-Before
2  
-{{ fail() }}
3  
-After
1  tests/loaderres/templates/foo/test.html
... ...
@@ -1 +0,0 @@
1  
-FOO
4  tests/loaderres/templates/syntaxerror.html
... ...
@@ -1,4 +0,0 @@
1  
-Foo
2  
-{% for item in broken %}
3  
-  ...
4  
-{% endif %}
1  tests/loaderres/templates/test.html
... ...
@@ -1 +0,0 @@
1  
-BAR
51  tests/test_debug.py
... ...
@@ -1,51 +0,0 @@
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  
-env = Environment(loader=filesystem_loader)
15  
-
16  
-
17  
-def test_runtime_error():
18  
-    '''
19  
->>> tmpl = env.get_template('broken.html')
20  
->>> tmpl.render(fail=lambda: 1 / 0)
21  
-Traceback (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)
26  
-ZeroDivisionError: integer division or modulo by zero
27  
-'''
28  
-
29  
-
30  
-def test_syntax_error():
31  
-    '''
32  
->>> tmpl = env.get_template('syntaxerror.html')
33  
-Traceback (most recent call last):
34  
-  ...
35  
-  File "tests/loaderres/templates/syntaxerror.html", line 4, in template
36  
-  {% endif %}
37  
-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'.
38  
-'''
39  
-
40  
-
41  
-def test_regular_syntax_error():
42  
-    '''
43  
->>> from jinja2.exceptions import TemplateSyntaxError
44  
->>> raise TemplateSyntaxError('wtf', 42)
45  
-Traceback (most recent call last):
46  
-  ...
47  
-  File "<doctest test_regular_syntax_error[1]>", line 1, in <module>
48  
-    raise TemplateSyntaxError('wtf', 42)
49  
-TemplateSyntaxError: wtf
50  
-  line 42
51  
-'''
173  tests/test_ext.py
... ...
@@ -1,173 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for some extensions
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-import re
10  
-from jinja2 import Environment, nodes
11  
-from jinja2.ext import Extension
12  
-from jinja2.lexer import Token, count_newlines
13  
-
14  
-
15  
-importable_object = 23
16  
-
17  
-
18  
-_gettext_re = re.compile(r'_\((.*?)\)(?s)')
19  
-
20  
-
21  
-class TestExtension(Extension):
22  
-    tags = set(['test'])
23  
-    ext_attr = 42
24  
-
25  
-    def parse(self, parser):
26  
-        return nodes.Output([self.call_method('_dump', [
27  
-            nodes.EnvironmentAttribute('sandboxed'),
28  
-            self.attr('ext_attr'),
29  
-            nodes.ImportedName(__name__ + '.importable_object'),
30  
-            nodes.ContextReference()
31  
-        ])]).set_lineno(parser.stream.next().lineno)
32  
-
33  
-    def _dump(self, sandboxed, ext_attr, imported_object, context):
34  
-        return '%s|%s|%s|%s' % (
35  
-            sandboxed,
36  
-            ext_attr,
37  
-            imported_object,
38  
-            context.blocks
39  
-        )
40  
-
41  
-
42  
-class PreprocessorExtension(Extension):
43  
-
44  
-    def preprocess(self, source, name, filename=None):
45  
-        return source.replace('[[TEST]]', '({{ foo }})')
46  
-
47  
-
48  
-class StreamFilterExtension(Extension):
49  
-
50  
-    def filter_stream(self, stream):
51  
-        for token in stream:
52  
-            if token.type == 'data':
53  
-                for t in self.interpolate(token):
54  
-                    yield t
55  
-            else:
56  
-                yield token
57  
-
58  
-    def interpolate(self, token):
59  
-        pos = 0
60  
-        end = len(token.value)
61  
-        lineno = token.lineno
62  
-        while 1:
63  
-            match = _gettext_re.search(token.value, pos)
64  
-            if match is None:
65  
-                break
66  
-            value = token.value[pos:match.start()]
67  
-            if value:
68  
-                yield Token(lineno, 'data', value)
69  
-            lineno += count_newlines(token.value)
70  
-            yield Token(lineno, 'variable_begin', None)
71  
-            yield Token(lineno, 'name', 'gettext')
72  
-            yield Token(lineno, 'lparen', None)
73  
-            yield Token(lineno, 'string', match.group(1))
74  
-            yield Token(lineno, 'rparen', None)
75  
-            yield Token(lineno, 'variable_end', None)
76  
-            pos = match.end()
77  
-        if pos < end:
78  
-            yield Token(lineno, 'data', token.value[pos:])
79  
-
80  
-
81  
-def test_loop_controls():
82  
-    env = Environment(extensions=['jinja2.ext.loopcontrols'])
83  
-
84  
-    tmpl = env.from_string('''
85  
-        {%- for item in [1, 2, 3, 4] %}
86  
-            {%- if item % 2 == 0 %}{% continue %}{% endif -%}
87  
-            {{ item }}
88  
-        {%- endfor %}''')
89  
-    assert tmpl.render() == '13'
90  
-
91  
-    tmpl = env.from_string('''
92  
-        {%- for item in [1, 2, 3, 4] %}
93  
-            {%- if item > 2 %}{% break %}{% endif -%}
94  
-            {{ item }}
95  
-        {%- endfor %}''')
96  
-    assert tmpl.render() == '12'
97  
-
98  
-
99  
-def test_do():
100  
-    env = Environment(extensions=['jinja2.ext.do'])
101  
-    tmpl = env.from_string('''
102  
-        {%- set items = [] %}
103  
-        {%- for char in "foo" %}
104  
-            {%- do items.append(loop.index0 ~ char) %}
105  
-        {%- endfor %}{{ items|join(', ') }}''')
106  
-    assert tmpl.render() == '0f, 1o, 2o'
107  
-
108  
-
109  
-def test_with():
110  
-    env = Environment(extensions=['jinja2.ext.with_'])
111  
-    tmpl = env.from_string('''\
112  
-    {% with a=42, b=23 -%}
113  
-        {{ a }} = {{ b }}
114  
-    {% endwith -%}
115  
-        {{ a }} = {{ b }}\
116  
-    ''')
117  
-    assert [x.strip() for x in tmpl.render(a=1, b=2).splitlines()] \
118  
-        == ['42 = 23', '1 = 2']
119  
-
120  
-
121  
-def test_extension_nodes():
122  
-    env = Environment(extensions=[TestExtension])
123  
-    tmpl = env.from_string('{% test %}')
124  
-    assert tmpl.render() == 'False|42|23|{}'
125  
-
126  
-
127  
-def test_identifier():
128  
-    assert TestExtension.identifier == __name__ + '.TestExtension'
129  
-
130  
-
131  
-def test_rebinding():
132  
-    original = Environment(extensions=[TestExtension])
133  
-    overlay = original.overlay()
134  
-    for env in original, overlay:
135  
-        for ext in env.extensions.itervalues():
136  
-            assert ext.environment is env
137  
-
138  
-
139  
-def test_preprocessor_extension():
140  
-    env = Environment(extensions=[PreprocessorExtension])
141  
-    tmpl = env.from_string('{[[TEST]]}')
142  
-    assert tmpl.render(foo=42) == '{(42)}'
143  
-
144  
-
145  
-def test_streamfilter_extension():
146  
-    env = Environment(extensions=[StreamFilterExtension])
147  
-    env.globals['gettext'] = lambda x: x.upper()
148  
-    tmpl = env.from_string('Foo _(bar) Baz')
149  
-    out = tmpl.render()
150  
-    assert out == 'Foo BAR Baz'
151  
-
152  
-
153  
-class WithExtension(Extension):
154  
-    tags = frozenset(['with'])
155  
-
156  
-    def parse(self, parser):
157  
-        lineno = parser.stream.next().lineno
158  
-        value = parser.parse_expression()
159  
-        parser.stream.expect('name:as')
160  
-        name = parser.stream.expect('name')
161  
-
162  
-        body = parser.parse_statements(['name:endwith'], drop_needle=True)
163  
-        body.insert(0, nodes.Assign(nodes.Name(name.value, 'store'), value))
164  
-        return nodes.Scope(body)
165  
-
166  
-
167  
-def test_with_extension():
168  
-    env = Environment(extensions=[WithExtension])
169  
-    t = env.from_string('{{ a }}{% with 2 as a %}{{ a }}{% endwith %}{{ a }}')
170  
-    assert t.render(a=1) == '121'
171  
-
172  
-    t = env.from_string('{% with 2 as a %}{{ a }}{% endwith %}{{ a }}')
173  
-    assert t.render(a=3) == '23'
328  tests/test_filters.py
... ...
@@ -1,328 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for the filters
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-from jinja2 import Markup, Environment
10  
-
11  
-env = Environment()
12  
-
13  
-
14  
-CAPITALIZE = '''{{ "foo bar"|capitalize }}'''
15  
-CENTER = '''{{ "foo"|center(9) }}'''
16  
-DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\
17  
-{{ false|default('no', true) }}|{{ given|default("no") }}'''
18  
-DICTSORT = '''{{ foo|dictsort }}|\
19  
-{{ foo|dictsort(true) }}|\
20  
-{{ foo|dictsort(false, 'value') }}'''
21  
-BATCH = '''{{ foo|batch(3)|list }}|{{ foo|batch(3, 'X')|list }}'''
22  
-SLICE = '''{{ foo|slice(3)|list }}|{{ foo|slice(3, 'X')|list }}'''
23  
-ESCAPE = '''{{ '<">&'|escape }}'''
24  
-STRIPTAGS = '''{{ foo|striptags }}'''
25  
-FILESIZEFORMAT = '{{ 100|filesizeformat }}|\
26  
-{{ 1000|filesizeformat }}|\
27  
-{{ 1000000|filesizeformat }}|\
28  
-{{ 1000000000|filesizeformat }}|\
29  
-{{ 1000000000000|filesizeformat }}|\
30  
-{{ 100|filesizeformat(true) }}|\
31  
-{{ 1000|filesizeformat(true) }}|\
32  
-{{ 1000000|filesizeformat(true) }}|\
33  
-{{ 1000000000|filesizeformat(true) }}|\
34  
-{{ 1000000000000|filesizeformat(true) }}'
35  
-FIRST = '''{{ foo|first }}'''
36  
-FLOAT = '''{{ "42"|float }}|{{ "ajsghasjgd"|float }}|{{ "32.32"|float }}'''
37  
-FORMAT = '''{{ "%s|%s"|format("a", "b") }}'''
38  
-INDENT = '''{{ foo|indent(2) }}|{{ foo|indent(2, true) }}'''
39  
-INT = '''{{ "42"|int }}|{{ "ajsghasjgd"|int }}|{{ "32.32"|int }}'''
40  
-JOIN = '''{{ [1, 2, 3]|join("|") }}'''
41  
-LAST = '''{{ foo|last }}'''
42  
-LENGTH = '''{{ "hello world"|length }}'''
43  
-LOWER = '''{{ "FOO"|lower }}'''
44  
-PPRINT = '''{{ data|pprint }}'''
45  
-RANDOM = '''{{ seq|random }}'''
46  
-REVERSE = '''{{ "foobar"|reverse|join }}|{{ [1, 2, 3]|reverse|list }}'''
47  
-STRING = '''{{ range(10)|string }}'''
48  
-TITLE = '''{{ "foo bar"|title }}'''
49  
-TRIM = '''{{ "      foo       "|trim }}'''
50  
-TRUNCATE = '''{{ data|truncate(15, true, ">>>") }}|\
51  
-{{ data|truncate(15, false, ">>>") }}|\
52  
-{{ smalldata|truncate(15) }}'''
53  
-UPPER = '''{{ "foo"|upper }}'''
54  
-URLIZE = '''{{ "foo http://www.example.com/ bar"|urlize }}'''
55  
-WORDCOUNT = '''{{ "foo bar baz"|wordcount }}'''
56  
-BLOCK = '''{% filter lower|escape %}<HEHE>{% endfilter %}'''
57  
-CHAINING = '''{{ ['<foo>', '<bar>']|first|upper|escape }}'''
58  
-SUM = '''{{ [1, 2, 3, 4, 5, 6]|sum }}'''
59  
-ABS = '''{{ -1|abs }}|{{ 1|abs }}'''
60  
-ROUND = '''{{ 2.7|round }}|{{ 2.1|round }}|\
61  
-{{ 2.1234|round(2, 'floor') }}|{{ 2.1|round(0, 'ceil') }}'''
62  
-XMLATTR = '''{{ {'foo': 42, 'bar': 23, 'fish': none,
63  
-'spam': missing, 'blub:blub': '<?>'}|xmlattr }}'''
64  
-SORT1 = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''
65  
-GROUPBY = '''{% for grouper, list in [{'foo': 1, 'bar': 2},
66  
-                 {'foo': 2, 'bar': 3},
67  
-                 {'foo': 1, 'bar': 1},
68  
-                 {'foo': 3, 'bar': 4}]|groupby('foo') -%}
69  
-{{ grouper }}: {{ list|join(', ') }}
70  
-{% endfor %}'''
71  
-FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''
72  
-SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''
73  
-
74  
-
75  
-def test_capitalize():
76  
-    tmpl = env.from_string(CAPITALIZE)
77  
-    assert tmpl.render() == 'Foo bar'
78  
-
79  
-
80  
-def test_center():
81  
-    tmpl = env.from_string(CENTER)
82  
-    assert tmpl.render() == '   foo   '
83  
-
84  
-
85  
-def test_default():
86  
-    tmpl = env.from_string(DEFAULT)
87  
-    assert tmpl.render(given='yes') == 'no|False|no|yes'
88  
-
89  
-
90  
-def test_dictsort():
91  
-    tmpl = env.from_string(DICTSORT)
92  
-    out = tmpl.render(foo={"aa": 0, "b": 1, "c": 2, "AB": 3})
93  
-    assert out == ("[('aa', 0), ('AB', 3), ('b', 1), ('c', 2)]|"
94  
-                   "[('AB', 3), ('aa', 0), ('b', 1), ('c', 2)]|"
95  
-                   "[('aa', 0), ('b', 1), ('c', 2), ('AB', 3)]")
96  
-
97  
-
98  
-def test_batch():
99  
-    tmpl = env.from_string(BATCH)
100  
-    out = tmpl.render(foo=range(10))
101  
-    assert out == ("[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]|"
102  
-                   "[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 'X', 'X']]")
103  
-
104  
-
105  
-def test_slice():
106  
-    tmpl = env.from_string(SLICE)
107  
-    out = tmpl.render(foo=range(10))
108  
-    assert out == ("[[0, 1, 2, 3], [4, 5, 6], [7, 8, 9]]|"
109  
-                   "[[0, 1, 2, 3], [4, 5, 6, 'X'], [7, 8, 9, 'X']]")
110  
-
111  
-
112  
-def test_escape():
113  
-    tmpl = env.from_string(ESCAPE)
114  
-    out = tmpl.render()
115  
-    assert out == '&lt;&#34;&gt;&amp;'
116  
-
117  
-
118  
-def test_striptags():
119  
-    tmpl = env.from_string(STRIPTAGS)
120  
-    out = tmpl.render(foo='  <p>just a small   \n <a href="#">'
121  
-                      'example</a> link</p>\n<p>to a webpage</p> '
122  
-                      '<!-- <p>and some commented stuff</p> -->')
123  
-    assert out == 'just a small example link to a webpage'
124  
-
125  
-
126  
-def test_filesizeformat():
127  
-    tmpl = env.from_string(FILESIZEFORMAT)
128  
-    out = tmpl.render()
129  
-    assert out == (
130  
-        '100 Bytes|1.0 KB|1.0 MB|1.0 GB|1000.0 GB|'
131  
-        '100 Bytes|1000 Bytes|976.6 KiB|953.7 MiB|931.3 GiB'
132  
-    )
133  
-
134  
-
135  
-def test_first():
136  
-    tmpl = env.from_string(FIRST)
137  
-    out = tmpl.render(foo=range(10))
138  
-    assert out == '0'
139  
-
140  
-
141  
-def test_float():
142  
-    tmpl = env.from_string(FLOAT)
143  
-    out = tmpl.render()
144  
-    assert out == '42.0|0.0|32.32'
145  
-
146  
-
147  
-def test_format():
148  
-    tmpl = env.from_string(FORMAT)
149  
-    out = tmpl.render()
150  
-    assert out == 'a|b'
151  
-
152  
-
153  
-def test_indent():
154  
-    tmpl = env.from_string(INDENT)
155  
-    text = '\n'.join([' '.join(['foo', 'bar'] * 2)] * 2)
156  
-    out = tmpl.render(foo=text)
157  
-    assert out == ('foo bar foo bar\n  foo bar foo bar|  '
158  
-                   'foo bar foo bar\n  foo bar foo bar')
159  
-
160  
-
161  
-def test_int():
162  
-    tmpl = env.from_string(INT)
163  
-    out = tmpl.render()
164  
-    assert out == '42|0|32'
165  
-
166  
-
167  
-def test_join():
168  
-    tmpl = env.from_string(JOIN)
169  
-    out = tmpl.render()
170  
-    assert out == '1|2|3'
171  
-
172  
-    env2 = Environment(autoescape=True)
173  
-    tmpl = env2.from_string('{{ ["<foo>", "<span>foo</span>"|safe]|join }}')
174  
-    assert tmpl.render() == '&lt;foo&gt;<span>foo</span>'
175  
-
176  
-
177  
-def test_last():
178  
-    tmpl = env.from_string(LAST)
179  
-    out = tmpl.render(foo=range(10))
180  
-    assert out == '9'
181  
-
182  
-
183  
-def test_length():
184  
-    tmpl = env.from_string(LENGTH)
185  
-    out = tmpl.render()
186  
-    assert out == '11'
187  
-
188  
-
189  
-def test_lower():
190  
-    tmpl = env.from_string(LOWER)
191  
-    out = tmpl.render()
192  
-    assert out == 'foo'
193  
-
194  
-
195  
-def test_pprint():
196  
-    from pprint import pformat
197  
-    tmpl = env.from_string(PPRINT)
198  
-    data = range(1000)
199  
-    assert tmpl.render(data=data) == pformat(data)
200  
-
201  
-
202  
-def test_random():
203  
-    tmpl = env.from_string(RANDOM)
204  
-    seq = range(100)
205  
-    for _ in range(10):
206  
-        assert int(tmpl.render(seq=seq)) in seq
207  
-
208  
-
209  
-def test_reverse():
210  
-    tmpl = env.from_string(REVERSE)
211  
-    assert tmpl.render() == 'raboof|[3, 2, 1]'
212  
-
213  
-
214  
-def test_string():
215  
-    tmpl = env.from_string(STRING)
216  
-    assert tmpl.render(foo=range(10)) == unicode(xrange(10))
217  
-
218  
-
219  
-def test_title():
220  
-    tmpl = env.from_string(TITLE)
221  
-    assert tmpl.render() == "Foo Bar"
222  
-
223  
-
224  
-def test_truncate():
225  
-    tmpl = env.from_string(TRUNCATE)
226  
-    out = tmpl.render(data='foobar baz bar' * 1000,
227  
-                      smalldata='foobar baz bar')
228  
-    assert out == 'foobar baz barf>>>|foobar baz >>>|foobar baz bar'
229  
-
230  
-
231  
-def test_upper():
232  
-    tmpl = env.from_string(UPPER)
233  
-    assert tmpl.render() == 'FOO'
234  
-
235  
-
236  
-def test_urlize():
237  
-    tmpl = env.from_string(URLIZE)
238  
-    assert tmpl.render() == 'foo <a href="http://www.example.com/">'\
239  
-                            'http://www.example.com/</a> bar'
240  
-
241  
-
242  
-def test_wordcount():
243  
-    tmpl = env.from_string(WORDCOUNT)
244  
-    assert tmpl.render() == '3'
245  
-
246  
-
247  
-def test_block():
248  
-    tmpl = env.from_string(BLOCK)
249  
-    assert tmpl.render() == '&lt;hehe&gt;'
250  
-
251  
-
252  
-def test_chaining():
253  
-    tmpl = env.from_string(CHAINING)
254  
-    assert tmpl.render() == '&lt;FOO&gt;'
255  
-
256  
-
257  
-def test_sum():
258  
-    tmpl = env.from_string(SUM)
259  
-    assert tmpl.render() == '21'
260  
-
261  
-
262  
-def test_abs():
263  
-    tmpl = env.from_string(ABS)
264  
-    return tmpl.render() == '1|1'
265  
-
266  
-
267  
-def test_round():
268  
-    tmpl = env.from_string(ROUND)
269  
-    return tmpl.render() == '3.0|2.0|2.1|3.0'
270  
-
271  
-
272  
-def test_xmlattr():
273  
-    tmpl = env.from_string(XMLATTR)
274  
-    out = tmpl.render().split()
275  
-    assert len(out) == 3
276  
-    assert 'foo="42"' in out
277  
-    assert 'bar="23"' in out
278  
-    assert 'blub:blub="&lt;?&gt;"' in out
279  
-
280  
-
281  
-def test_sort1():
282  
-    tmpl = env.from_string(SORT1)
283  
-    assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'
284  
-
285  
-
286  
-def test_groupby():
287  
-    tmpl = env.from_string(GROUPBY)
288  
-    assert tmpl.render().splitlines() == [
289  
-        "1: {'foo': 1, 'bar': 2}, {'foo': 1, 'bar': 1}",
290  
-        "2: {'foo': 2, 'bar': 3}",
291  
-        "3: {'foo': 3, 'bar': 4}"
292  
-    ]
293  
-
294  
-
295  
-def test_filtertag():
296  
-    tmpl = env.from_string(FILTERTAG)
297  
-    assert tmpl.render() == 'fooBAR'
298  
-
299  
-
300  
-def test_replace():
301  
-    env = Environment()
302  
-    tmpl = env.from_string('{{ string|replace("o", 42) }}')
303  
-    assert tmpl.render(string='<foo>') == '<f4242>'
304  
-
305  
-    env = Environment(autoescape=True)
306  
-    tmpl = env.from_string('{{ string|replace("o", 42) }}')
307  
-    assert tmpl.render(string='<foo>') == '&lt;f4242&gt;'
308  
-    tmpl = env.from_string('{{ string|replace("<", 42) }}')
309  
-    assert tmpl.render(string='<foo>') == '42foo&gt;'
310  
-    tmpl = env.from_string('{{ string|replace("o", ">x<") }}')
311  
-    assert tmpl.render(string=Markup('foo')) == 'f&gt;x&lt;&gt;x&lt;'
312  
-
313  
-
314  
-def test_forceescape():
315  
-    tmpl = env.from_string('{{ x|forceescape }}')
316  
-    assert tmpl.render(x=Markup('<div />')) == u'&lt;div /&gt;'
317  
-
318  
-
319  
-def test_safe():
320  
-    env = Environment(autoescape=True)
321  
-    tmpl = env.from_string('{{ "<div>foo</div>"|safe }}')
322  
-    assert tmpl.render() == '<div>foo</div>'
323  
-    tmpl = env.from_string('{{ "<div>foo</div>" }}')
324  
-    assert tmpl.render() == '&lt;div&gt;foo&lt;/div&gt;'
325  
-
326  
-
327  
-def test_sort2():
328  
-    assert env.from_string(SORT2).render() == "['Bar', 'blah', 'foo']"
190  tests/test_forloop.py
... ...
@@ -1,190 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for loop functions
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-from jinja2 import Environment
10  
-from jinja2.exceptions import UndefinedError, TemplateSyntaxError
11  
-
12  
-from nose.tools import assert_raises
13  
-
14  
-env = Environment()
15  
-
16  
-
17  
-SIMPLE = '''{% for item in seq %}{{ item }}{% endfor %}'''
18  
-ELSE = '''{% for item in seq %}XXX{% else %}...{% endfor %}'''
19  
-EMPTYBLOCKS = '''<{% for item in seq %}{% else %}{% endfor %}>'''
20  
-CONTEXTVARS = '''{% for item in seq %}\
21  
-{{ loop.index }}|{{ loop.index0 }}|{{ loop.revindex }}|{{
22  
-   loop.revindex0 }}|{{ loop.first }}|{{ loop.last }}|{{
23  
-   loop.length }}###{% endfor %}'''
24  
-CYCLING = '''{% for item in seq %}{{ loop.cycle('<1>', '<2>') }}{% endfor %}\
25  
-{% for item in seq %}{{ loop.cycle(*through) }}{% endfor %}'''
26  
-SCOPE = '''{% for item in seq %}{% endfor %}{{ item }}'''
27  
-VARLEN = '''{% for item in iter %}{{ item }}{% endfor %}'''
28  
-NONITER = '''{% for item in none %}...{% endfor %}'''
29  
-RECURSIVE = '''{% for item in seq recursive -%}
30  
-    [{{ item.a }}{% if item.b %}<{{ loop(item.b) }}>{% endif %}]
31  
-{%- endfor %}'''
32  
-LOOPLOOP = '''{% for row in table %}
33  
-    {%- set rowloop = loop -%}
34  
-    {% for cell in row -%}
35  
-        [{{ rowloop.index }}|{{ loop.index }}]
36  
-    {%- endfor %}
37  
-{%- endfor %}'''
38  
-LOOPERROR1 = '''\
39  
-{% for item in [1] if loop.index == 0 %}...{% endfor %}'''
40  
-LOOPERROR2 = '''\
41  
-{% for item in [] %}...{% else %}{{ loop }}{% endfor %}'''
42  
-LOOPFILTER = '''\
43  
-{% for item in range(10) if item is even %}[{{ item }}]{% endfor %}'''
44  
-EXTENDEDLOOPFILTER = '''\
45  
-{% for item in range(10) if item is even %}[{{ loop.index
46  
-}}:{{ item }}]{% endfor %}'''
47  
-LOOPUNASSIGNABLE = '''\
48  
-{% for loop in seq %}...{% endfor %}'''
49  
-
50  
-
51  
-def test_simple():
52  
-    tmpl = env.from_string(SIMPLE)
53  
-    assert tmpl.render(seq=range(10)) == '0123456789'
54  
-
55  
-
56  
-def test_else():
57  
-    tmpl = env.from_string(ELSE)
58  
-    assert tmpl.render() == '...'
59  
-
60  
-
61  
-def test_empty_blocks():
62  
-    tmpl = env.from_string(EMPTYBLOCKS)
63  
-    assert tmpl.render() == '<>'
64  
-
65  
-
66  
-def test_context_vars():
67  
-    tmpl = env.from_string(CONTEXTVARS)
68  
-    one, two, _ = tmpl.render(seq=[0, 1]).split('###')
69  
-    (one_index, one_index0, one_revindex, one_revindex0, one_first,
70  
-     one_last, one_length) = one.split('|')
71  
-    (two_index, two_index0, two_revindex, two_revindex0, two_first,
72  
-     two_last, two_length) = two.split('|')
73  
-
74  
-    assert int(one_index) == 1 and int(two_index) == 2
75  
-    assert int(one_index0) == 0 and int(two_index0) == 1
76  
-    assert int(one_revindex) == 2 and int(two_revindex) == 1
77  
-    assert int(one_revindex0) == 1 and int(two_revindex0) == 0
78  
-    assert one_first == 'True' and two_first == 'False'
79  
-    assert one_last == 'False' and two_last == 'True'
80  
-    assert one_length == two_length == '2'
81  
-
82  
-
83  
-def test_cycling():
84  
-    tmpl = env.from_string(CYCLING)
85  
-    output = tmpl.render(seq=range(4), through=('<1>', '<2>'))
86  
-    assert output == '<1><2>' * 4
87  
-
88  
-
89  
-def test_scope():
90  
-    tmpl = env.from_string(SCOPE)
91  
-    output = tmpl.render(seq=range(10))
92  
-    assert not output
93  
-
94  
-
95  
-def test_varlen():
96  
-    def inner():
97  
-        for item in range(5):
98  
-            yield item
99  
-    tmpl = env.from_string(VARLEN)
100  
-    output = tmpl.render(iter=inner())
101  
-    assert output == '01234'
102  
-
103  
-
104  
-def test_noniter():
105  
-    tmpl = env.from_string(NONITER)
106  
-    assert_raises(TypeError, tmpl.render)
107  
-
108  
-
109  
-def test_recursive():
110  
-    tmpl = env.from_string(RECURSIVE)
111  
-    assert tmpl.render(seq=[
112  
-        dict(a=1, b=[dict(a=1), dict(a=2)]),
113  
-        dict(a=2, b=[dict(a=1), dict(a=2)]),
114  
-        dict(a=3, b=[dict(a='a')])
115  
-    ]) == '[1<[1][2]>][2<[1][2]>][3<[a]>]'
116  
-
117  
-
118  
-def test_looploop():
119  
-    tmpl = env.from_string(LOOPLOOP)
120  
-    assert tmpl.render(table=['ab', 'cd']) == '[1|1][1|2][2|1][2|2]'
121  
-
122  
-
123  
-def test_reversed_bug():
124  
-    tmpl = env.from_string('{% for i in items %}{{ i }}{% if not loop.last %}'
125  
-                           ',{% endif %}{% endfor %}')
126  
-    assert tmpl.render(items=reversed([3, 2, 1])) == '1,2,3'
127  
-
128  
-
129  
-def test_loop_errors():
130  
-    tmpl = env.from_string(LOOPERROR1)
131  
-    assert_raises(UndefinedError, tmpl.render)
132  
-    tmpl = env.from_string(LOOPERROR2)
133  
-    assert tmpl.render() == ''
134  
-
135  
-
136  
-def test_loop_filter():
137  
-    tmpl = env.from_string(LOOPFILTER)
138  
-    assert tmpl.render() == '[0][2][4][6][8]'
139  
-    tmpl = env.from_string(EXTENDEDLOOPFILTER)
140  
-    assert tmpl.render() == '[1:0][2:2][3:4][4:6][5:8]'
141  
-
142  
-
143  
-def test_loop_unassignable():
144  
-    assert_raises(TemplateSyntaxError, env.from_string, LOOPUNASSIGNABLE)
145  
-
146  
-
147  
-def test_scoped_special_var():
148  
-    t = env.from_string('{% for s in seq %}[{{ loop.first }}{% for c in s %}'
149  
-                        '|{{ loop.first }}{% endfor %}]{% endfor %}')
150  
-    assert t.render(seq=('ab', 'cd')) == '[True|True|False][False|True|False]'
151  
-
152  
-
153  
-def test_scoped_loop_var():
154  
-    t = env.from_string('{% for x in seq %}{{ loop.first }}'
155  
-                        '{% for y in seq %}{% endfor %}{% endfor %}')
156  
-    assert t.render(seq='ab') == 'TrueFalse'
157  
-    t = env.from_string('{% for x in seq %}{% for y in seq %}'
158  
-                        '{{ loop.first }}{% endfor %}{% endfor %}')
159  
-    assert t.render(seq='ab') == 'TrueFalseTrueFalse'
160  
-
161  
-
162  
-def test_recursive_empty_loop_iter():
163  
-    t = env.from_string('''
164  
-    {%- for item in foo recursive -%}{%- endfor -%}
165  
-    ''')
166  
-    assert t.render(dict(foo=[])) == ''
167  
-
168  
-
169  
-def test_call_in_loop():
170  
-    t = env.from_string('''
171  
-    {%- macro do_something() -%}
172  
-        [{{ caller() }}]
173  
-    {%- endmacro %}
174  
-
175  
-    {%- for i in [1, 2, 3] %}
176  
-        {%- call do_something() -%}
177  
-            {{ i }}
178  
-        {%- endcall %}
179  
-    {%- endfor -%}
180  
-    ''')
181  
-    assert t.render() == '[1][2][3]'
182  
-
183  
-
184  
-def test_scoping_bug():
185  
-    t = env.from_string('''
186  
-    {%- for item in foo %}...{{ item }}...{% endfor %}
187  
-    {%- macro item(a) %}...{{ a }}...{% endmacro %}
188  
-    {{- item(2) -}}
189  
-    ''')
190  
-    assert t.render(foo=(1,)) == '...1......2...'
73  tests/test_heavy.py
... ...
@@ -1,73 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    Heavy tests
4  
-    ~~~~~~~~~~~
5  
-
6  
-    The tests in this module test complex Jinja2 situations to ensure
7  
-    corner cases (unfortunately mostly undocumented scoping behavior)
8  
-    does not change between versions.
9  
-
10  
-    :copyright: Copyright 2009 by the Jinja Team.
11  
-    :license: BSD.
12  
-"""
13  
-from jinja2 import Environment
14  
-env = Environment()
15  
-
16  
-
17  
-def test_assigned_scoping():
18  
-    t = env.from_string('''
19  
-    {%- for item in (1, 2, 3, 4) -%}
20  
-        [{{ item }}]
21  
-    {%- endfor %}
22  
-    {{- item -}}
23  
-    ''')
24  
-    assert t.render(item=42) == '[1][2][3][4]42'
25  
-
26  
-    t = env.from_string('''
27  
-    {%- for item in (1, 2, 3, 4) -%}
28  
-        [{{ item }}]
29  
-    {%- endfor %}
30  
-    {%- set item = 42 %}
31  
-    {{- item -}}
32  
-    ''')
33  
-    assert t.render() == '[1][2][3][4]42'
34  
-
35  
-    t = env.from_string('''
36  
-    {%- set item = 42 %}
37  
-    {%- for item in (1, 2, 3, 4) -%}
38  
-        [{{ item }}]
39  
-    {%- endfor %}
40  
-    {{- item -}}
41  
-    ''')
42  
-    assert t.render() == '[1][2][3][4]42'
43  
-
44  
-
45  
-def test_closure_scoping():
46  
-    t = env.from_string('''
47  
-    {%- set wrapper = "<FOO>" %}
48  
-    {%- for item in (1, 2, 3, 4) %}
49  
-        {%- macro wrapper() %}[{{ item }}]{% endmacro %}
50  
-        {{- wrapper() }}
51  
-    {%- endfor %}
52  
-    {{- wrapper -}}
53  
-    ''')
54  
-    assert t.render() == '[1][2][3][4]<FOO>'
55  
-
56  
-    t = env.from_string('''
57  
-    {%- for item in (1, 2, 3, 4) %}
58  
-        {%- macro wrapper() %}[{{ item }}]{% endmacro %}
59  
-        {{- wrapper() }}
60  
-    {%- endfor %}
61  
-    {%- set wrapper = "<FOO>" %}
62  
-    {{- wrapper -}}
63  
-    ''')
64  
-    assert t.render() == '[1][2][3][4]<FOO>'
65  
-
66  
-    t = env.from_string('''
67  
-    {%- for item in (1, 2, 3, 4) %}
68  
-        {%- macro wrapper() %}[{{ item }}]{% endmacro %}
69  
-        {{- wrapper() }}
70  
-    {%- endfor %}
71  
-    {{- wrapper -}}
72  
-    ''')
73  
-    assert t.render(wrapper=23) == '[1][2][3][4]23'
114  tests/test_i18n.py
... ...
@@ -1,114 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for the i18n functions
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-from jinja2 import Environment, DictLoader, contextfunction
10  
-from jinja2.exceptions import TemplateAssertionError
11  
-
12  
-from nose.tools import assert_raises
13  
-
14  
-templates = {
15  
-    'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'
16  
-                   '{% block body %}{% endblock %}',
17  
-    'child.html': '{% extends "master.html" %}{% block body %}'
18  
-                  '{% trans %}watch out{% endtrans %}{% endblock %}',
19  
-    'plural.html': '{% trans user_count %}One user online{% pluralize %}'
20  
-                   '{{ user_count }} users online{% endtrans %}',
21  
-    'stringformat.html': '{{ _("User: %d")|format(user_count) }}'
22  
-}
23  
-
24  
-
25  
-languages = {
26  
-    'de': {
27  
-        'missing':                      'fehlend',
28  
-        'watch out':                    'pass auf',
29  
-        'One user online':              'Ein Benutzer online',
30  
-        '%(user_count)s users online':  '%(user_count)s Benutzer online',
31  
-        'User: %d':                     'Benutzer: %d'
32  
-    }
33  
-}
34  
-
35  
-
36  
-@contextfunction
37  
-def gettext(context, string):
38  
-    language = context.get('LANGUAGE', 'en')
39  
-    return languages.get(language, {}).get(string, string)
40  
-
41  
-
42  
-@contextfunction
43  
-def ngettext(context, s, p, n):
44  
-    language = context.get('LANGUAGE', 'en')
45  
-    if n != 1:
46  
-        return languages.get(language, {}).get(p, p)
47  
-    return languages.get(language, {}).get(s, s)
48  
-
49  
-
50  
-i18n_env = Environment(
51  
-    loader=DictLoader(templates),
52  
-    extensions=['jinja2.ext.i18n']
53  
-)
54  
-i18n_env.globals.update({
55  
-    '_':            gettext,
56  
-    'gettext':      gettext,
57  
-    'ngettext':     ngettext
58  
-})
59  
-
60  
-
61  
-def test_trans():
62  
-    tmpl = i18n_env.get_template('child.html')
63  
-    assert tmpl.render(LANGUAGE='de') == '<title>fehlend</title>pass auf'
64  
-
65  
-
66  
-def test_trans_plural():
67  
-    tmpl = i18n_env.get_template('plural.html')
68  
-    assert tmpl.render(LANGUAGE='de', user_count=1) == 'Ein Benutzer online'
69  
-    assert tmpl.render(LANGUAGE='de', user_count=2) == '2 Benutzer online'
70  
-
71  
-
72  
-def test_complex_plural():
73  
-    tmpl = i18n_env.from_string('{% trans foo=42, count=2 %}{{ count }} item{% '
74  
-                                'pluralize count %}{{ count }} items{% endtrans %}')
75  
-    assert tmpl.render() == '2 items'
76  
-    assert_raises(TemplateAssertionError, i18n_env.from_string,
77  
-                 '{% trans foo %}...{% pluralize bar %}...{% endtrans %}')
78  
-
79  
-
80  
-def test_trans_stringformatting():
81  
-    tmpl = i18n_env.get_template('stringformat.html')
82  
-    assert tmpl.render(LANGUAGE='de', user_count=5) == 'Benutzer: 5'
83  
-
84  
-
85  
-def test_extract():
86  
-    from jinja2.ext import babel_extract
87  
-    from StringIO import StringIO
88  
-    source = StringIO('''
89  
-    {{ gettext('Hello World') }}
90  
-    {% trans %}Hello World{% endtrans %}
91  
-    {% trans %}{{ users }} user{% pluralize %}{{ users }} users{% endtrans %}
92  
-    ''')
93  
-    assert list(babel_extract(source, ('gettext', 'ngettext', '_'), [], {})) == [
94  
-        (2, 'gettext', u'Hello World', []),
95  
-        (3, 'gettext', u'Hello World', []),
96  
-        (4, 'ngettext', (u'%(users)s user', u'%(users)s users', None), [])
97  
-    ]
98  
-
99  
-
100  
-def test_comment_extract():
101  
-    from jinja2.ext import babel_extract
102  
-    from StringIO import StringIO
103  
-    source = StringIO('''
104  
-    {# trans first #}
105  
-    {{ gettext('Hello World') }}
106  
-    {% trans %}Hello World{% endtrans %}{# trans second #}
107  
-    {#: third #}
108  
-    {% trans %}{{ users }} user{% pluralize %}{{ users }} users{% endtrans %}
109  
-    ''')
110  
-    assert list(babel_extract(source, ('gettext', 'ngettext', '_'), ['trans', ':'], {})) == [
111  
-        (3, 'gettext', u'Hello World', ['first']),
112  
-        (4, 'gettext', u'Hello World', ['second']),
113  
-        (6, 'ngettext', (u'%(users)s user', u'%(users)s users', None), ['third'])
114  
-    ]
50  tests/test_ifcondition.py
... ...
@@ -1,50 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for if conditions
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-
10  
-from jinja2 import Environment
11  
-env = Environment()
12  
-
13  
-
14  
-SIMPLE = '''{% if true %}...{% endif %}'''
15  
-ELIF = '''{% if false %}XXX{% elif true %}...{% else %}XXX{% endif %}'''
16  
-ELSE = '''{% if false %}XXX{% else %}...{% endif %}'''
17  
-EMPTY = '''[{% if true %}{% else %}{% endif %}]'''
18  
-
19  
-
20  
-def test_simple():
21  
-    tmpl = env.from_string(SIMPLE)
22  
-    assert tmpl.render() == '...'
23  
-
24  
-
25  
-def test_elif():
26  
-    tmpl = env.from_string(ELIF)
27  
-    assert tmpl.render() == '...'
28  
-
29  
-
30  
-def test_else():
31  
-    tmpl = env.from_string(ELSE)
32  
-    assert tmpl.render() == '...'
33  
-
34  
-
35  
-def test_empty():
36  
-    tmpl = env.from_string(EMPTY)
37  
-    assert tmpl.render() == '[]'
38  
-
39  
-
40  
-def test_complete():
41  
-    tmpl = env.from_string('{% if a %}A{% elif b %}B{% elif c == d %}'
42  
-                           'C{% else %}D{% endif %}')
43  
-    assert tmpl.render(a=0, b=False, c=42, d=42.0) == 'C'
44  
-
45  
-
46  
-def test_no_scope():
47  
-    tmpl = env.from_string('{% if a %}{% set foo = 1 %}{% endif %}{{ foo }}')
48  
-    assert tmpl.render(a=True) == '1'
49  
-    tmpl = env.from_string('{% if true %}{% set foo = 1 %}{% endif %}{{ foo }}')
50  
-    assert tmpl.render() == '1'
132  tests/test_imports.py
... ...
@@ -1,132 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for the imports and includes
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-from jinja2 import Environment, DictLoader
10  
-from jinja2.exceptions import TemplateNotFound, TemplatesNotFound
11  
-
12  
-from nose.tools import assert_raises
13  
-
14  
-
15  
-test_env = Environment(loader=DictLoader(dict(
16  
-    module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',
17  
-    header='[{{ foo }}|{{ 23 }}]',
18  
-    o_printer='({{ o }})'
19  
-)))
20  
-test_env.globals['bar'] = 23
21  
-
22  
-
23  
-def test_context_imports():
24  
-    t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')
25  
-    assert t.render(foo=42) == '[|23]'
26  
-    t = test_env.from_string('{% import "module" as m without context %}{{ m.test() }}')
27  
-    assert t.render(foo=42) == '[|23]'
28  
-    t = test_env.from_string('{% import "module" as m with context %}{{ m.test() }}')
29  
-    assert t.render(foo=42) == '[42|23]'
30  
-    t = test_env.from_string('{% from "module" import test %}{{ test() }}')
31  
-    assert t.render(foo=42) == '[|23]'
32  
-    t = test_env.from_string('{% from "module" import test without context %}{{ test() }}')
33  
-    assert t.render(foo=42) == '[|23]'
34  
-    t = test_env.from_string('{% from "module" import test with context %}{{ test() }}')
35  
-    assert t.render(foo=42) == '[42|23]'
36  
-
37  
-
38  
-def test_context_include():
39  
-    t = test_env.from_string('{% include "header" %}')
40  
-    assert t.render(foo=42) == '[42|23]'
41  
-    t = test_env.from_string('{% include "header" with context %}')
42  
-    assert t.render(foo=42) == '[42|23]'
43  
-    t = test_env.from_string('{% include "header" without context %}')
44  
-    assert t.render(foo=42) == '[|23]'
45  
-
46  
-
47  
-def test_choice_includes():
48  
-    t = test_env.from_string('{% include ["missing", "header"] %}')
49  
-    assert t.render(foo=42) == '[42|23]'
50  
-
51  
-    t = test_env.from_string('{% include ["missing", "missing2"] ignore missing %}')
52  
-    assert t.render(foo=42) == ''
53  
-
54  
-    t = test_env.from_string('{% include ["missing", "missing2"] %}')
55  
-    assert_raises(TemplateNotFound, t.render)
56  
-    try:
57  
-        t.render()
58  
-    except TemplatesNotFound, e:
59  
-        assert e.templates == ['missing', 'missing2']
60  
-        assert e.name == 'missing2'
61  
-    else:
62  
-        assert False, 'thou shalt raise'
63  
-
64  
-    def test_includes(t, **ctx):
65  
-        ctx['foo'] = 42
66  
-        assert t.render(ctx) == '[42|23]'
67  
-
68  
-    t = test_env.from_string('{% include ["missing", "header"] %}')
69  
-    test_includes(t)
70  
-    t = test_env.from_string('{% include x %}')
71  
-    test_includes(t, x=['missing', 'header'])
72  
-    t = test_env.from_string('{% include [x, "header"] %}')
73  
-    test_includes(t, x='missing')
74  
-    t = test_env.from_string('{% include x %}')
75  
-    test_includes(t, x='header')
76  
-    t = test_env.from_string('{% include x %}')
77  
-    test_includes(t, x='header')
78  
-    t = test_env.from_string('{% include [x] %}')
79  
-    test_includes(t, x='header')
80  
-
81  
-
82  
-def test_include_ignoring_missing():
83  
-    t = test_env.from_string('{% include "missing" %}')
84  
-    assert_raises(TemplateNotFound, t.render)
85  
-    for extra in '', 'with context', 'without context':
86  
-        t = test_env.from_string('{% include "missing" ignore missing ' +
87  
-                                 extra + ' %}')
88  
-        assert t.render() == ''
89  
-
90  
-
91  
-def test_context_include_with_overrides():
92  
-    env = Environment(loader=DictLoader(dict(
93  
-        main="{% for item in [1, 2, 3] %}{% include 'item' %}{% endfor %}",
94  
-        item="{{ item }}"
95  
-    )))
96  
-    assert env.get_template("main").render() == "123"
97  
-
98  
-
99  
-def test_trailing_comma():
100  
-    test_env.from_string('{% from "foo" import bar, baz with context %}')
101  
-    test_env.from_string('{% from "foo" import bar, baz, with context %}')
102  
-    test_env.from_string('{% from "foo" import bar, with context %}')
103  
-    test_env.from_string('{% from "foo" import bar, with, context %}')
104  
-    test_env.from_string('{% from "foo" import bar, with with context %}')
105  
-
106  
-
107  
-def test_exports():
108  
-    m = test_env.from_string('''
109  
-        {% macro toplevel() %}...{% endmacro %}
110  
-        {% macro __private() %}...{% endmacro %}
111  
-        {% set variable = 42 %}
112  
-        {% for item in [1] %}
113  
-            {% macro notthere() %}{% endmacro %}
114  
-        {% endfor %}
115  
-    ''').module
116  
-    assert m.toplevel() == '...'
117  
-    assert not hasattr(m, '__missing')
118  
-    assert m.variable == 42
119  
-    assert not hasattr(m, 'notthere')
120  
-
121  
-
122  
-def test_unoptimized_scopes():
123  
-    t = test_env.from_string("""
124  
-        {% macro outer(o) %}
125  
-        {% macro inner() %}
126  
-        {% include "o_printer" %}
127  
-        {% endmacro %}
128  
-        {{ inner() }}
129  
-        {% endmacro %}
130  
-        {{ outer("FOO") }}
131  
-    """)
132  
-    assert t.render().strip() == '(FOO)'
197  tests/test_inheritance.py
... ...
@@ -1,197 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-    unit test for the inheritance
4  
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5  
-
6  
-    :copyright: (c) 2009 by the Jinja Team.
7  
-    :license: BSD, see LICENSE for more details.
8  
-"""
9  
-
10  
-from jinja2 import Environment, DictLoader
11  
-from jinja2.exceptions import TemplateSyntaxError
12  
-
13  
-
14  
-LAYOUTTEMPLATE = '''\
15  
-|{% block block1 %}block 1 from layout{% endblock %}
16  
-|{% block block2 %}block 2 from layout{% endblock %}
17  
-|{% block block3 %}
18  
-{% block block4 %}nested block 4 from layout{% endblock %}
19  
-{% endblock %}|'''
20  
-
21  
-LEVEL1TEMPLATE = '''\
22  
-{% extends "layout" %}
23  
-{% block block1 %}block 1 from level1{% endblock %}'''
24  
-
25  
-LEVEL2TEMPLATE = '''\
26  
-{% extends "level1" %}