test_forloop.py
This file
Path
tests/test_forloop.py
81 lines · 2.5 KiB · Python
Last changed by
loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
History of this fileTake it
The walk stopped after 200 commits: lines older than e98c5f5 point at it.
[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
lines 1–8why, one step back1# -*- coding: utf-8 -*-2"""3 unit test for loop functions4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~56 :copyright: 2007 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
line 9why, one step back9from py.test import raises[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
line 10why, one step back10loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
line 11why, one step back11[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
lines 12–17why, one step back12SIMPLE = '''{% for item in seq %}{{ item }}{% endfor %}'''13ELSE = '''{% for item in seq %}XXX{% else %}...{% endfor %}'''14EMPTYBLOCKS = '''<{% for item in seq %}{% else %}{% endfor %}>'''15CONTEXTVARS = '''{% for item in seq %}\16{{ loop.index }}|{{ loop.index0 }}|{{ loop.revindex }}|{{17 loop.revindex0 }}|{{ loop.first }}|{{ loop.last }}|{{loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
lines 18–20why, one step back18 loop.length }}###{% endfor %}'''19CYCLING = '''{% for item in seq %}{{ loop.cycle('<1>', '<2>') }}{% endfor %}\20{% for item in seq %}{{ loop.cycle(*through) }}{% endfor %}'''[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
line 21why, one step back21SCOPE = '''{% for item in seq %}{% endfor %}{{ item }}'''[svn] checked in changes regarding variable length iterationArmin Ronacherbefore adoption6dba4d6
line 22why, one step back22VARLEN = '''{% for item in iter %}{{ item }}{% endfor %}'''[svn] again some jinja updates, some minor performance and doc improvementsArmin Ronacherbefore adoption9bcd411
line 23why, one step back23NONITER = '''{% for item in none %}...{% endfor %}'''[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
lines 24–44why, one step back242526def test_simple(env):27 tmpl = env.from_string(SIMPLE)28 assert tmpl.render(seq=range(10)) == '0123456789'293031def test_else(env):32 tmpl = env.from_string(ELSE)33 assert tmpl.render() == '...'343536def test_empty_blocks(env):37 tmpl = env.from_string(EMPTYBLOCKS)38 assert tmpl.render() == '<>'394041def test_context_vars(env):42 tmpl = env.from_string(CONTEXTVARS)43 one, two, _ = tmpl.render(seq=[0, 1]).split('###')44 (one_index, one_index0, one_revindex, one_revindex0, one_first,loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
line 45why, one step back45 one_last, one_length) = one.split('|')[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
line 46why, one step back46 (two_index, two_index0, two_revindex, two_revindex0, two_first,loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
line 47why, one step back47 two_last, two_length) = two.split('|')[svn] updated documentation regarding "{% call %}" and documented speedup module. also fixed some minor bugs in the speedup moduleArmin Ronacherbefore adoptione98c5f5
lines 48–67why, one step back4849 assert int(one_index) == 1 and int(two_index) == 250 assert int(one_index0) == 0 and int(two_index0) == 151 assert int(one_revindex) == 2 and int(two_revindex) == 152 assert int(one_revindex0) == 1 and int(two_revindex0) == 053 assert one_first == 'True' and two_first == 'False'54 assert one_last == 'False' and two_last == 'True'55 assert one_length == two_length == '2'565758def test_cycling(env):59 tmpl = env.from_string(CYCLING)60 output = tmpl.render(seq=range(4), through=('<1>', '<2>'))61 assert output == '<1><2>' * 4626364def test_scope(env):65 tmpl = env.from_string(SCOPE)66 output = tmpl.render(seq=range(10))67 assert not output[svn] checked in changes regarding variable length iterationArmin Ronacherbefore adoption6dba4d6
lines 68–76why, one step back686970def test_varlen(env):71 def inner():72 for item in range(5):73 yield item74 tmpl = env.from_string(VARLEN)75 output = tmpl.render(iter=inner())76 assert output == '01234'[svn] again some jinja updates, some minor performance and doc improvementsArmin Ronacherbefore adoption9bcd411
lines 77–80why, one step back777879def test_noniter(env):80 tmpl = env.from_string(NONITER)loops and `tests` tests pass nowArmin Ronacherbefore adoption10f3ba2
line 81why, one step back81 raises(TypeError, tmpl.render)