Skip to content
Myr

Got rid of py.testisms.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 1b43b58 · Browse files · 21 files+210 added−448 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

21 files+210 added−448 removed

  • tests:+210 added−408 removed
  • other:+0 added−40 removed

21 files+210 added−448 removed

deleted:tests/conftest.py-163 removed
1# -*- coding: utf-8 -*-2"""3 conftest4 ~~~~~~~~56 Configure py.test for support stuff.78 :copyright: (c) 2009 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""1112import os13import sys14sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))1516import py17from jinja2 import Environment18from jinja2.loaders import BaseLoader19from jinja2.exceptions import TemplateNotFound202122NOSE = 'nose' in sys.modules23if NOSE:24 import inspect25 from nose import case2627 def runTest(self):28 args = list(self.arg)29 if 'env' in inspect.getargspec(self.test).args:30 args.insert(0, simple_env)31 self.test(*args)32 case.TestBase.runTest = runTest333435try:36 # This code adds support for coverage.py (see37 # http://nedbatchelder.com/code/modules/coverage.html).38 # It prints a coverage report for the modules specified in all39 # module globals (of the test modules) named "coverage_modules".4041 import coverage, atexit4243 IGNORED_MODULES = ['jinja2._speedups', 'jinja2.defaults',44 'jinja2.translators']4546 def report_coverage():47 coverage.stop()48 module_list = [49 mod for name, mod in sys.modules.copy().iteritems() if50 getattr(mod, '__file__', None) and51 name.startswith('jinja2.') and52 name not in IGNORED_MODULES53 ]54 module_list.sort()55 coverage.report(module_list)5657 def callback(option, opt_str, value, parser):58 atexit.register(report_coverage)59 coverage.erase()60 coverage.start()6162 py.test.config.addoptions('Test options', py.test.config.Option('-C',63 '--coverage', action='callback', callback=callback,64 help='Output information about code coverage (slow!)'))6566except ImportError:67 coverage = None686970class GlobalLoader(BaseLoader):71 # Should be overwritten by importing module (test file) in order to find TEMPLATE vars72 scope = globals()7374 def get_source(self, environment, name):75 try:76 return self.scope[name.upper() + 'TEMPLATE'], None, None77 except KeyError:78 raise TemplateNotFound(name)798081loader = GlobalLoader()82simple_env = Environment(trim_blocks=True, loader=loader, cache_size=0)838485class Directory(py.test.collect.Directory):8687 def run(self):88 rv = super(Directory, self).run()89 if self.fspath.basename == 'tests':90 rv.append('doctests')91 return rv9293 def join(self, name):94 if name == 'doctests':95 return JinjaDocTestModule(name, parent=self)96 return super(Directory, self).join(name)979899class Module(py.test.collect.Module):100101 def __init__(self, *args, **kwargs):102 self.env = simple_env103 super(Module, self).__init__(*args, **kwargs)104105 def makeitem(self, name, obj, usefilters=True):106 if name.startswith('test_'):107 if hasattr(obj, 'func_code'):108 return JinjaTestFunction(name, parent=self)109 elif isinstance(obj, basestring):110 return JinjaDocTest(name, parent=self)111112113class JinjaTestFunction(py.test.collect.Function):114115 def execute(self, target, *args):116 loader.scope = target.func_globals117 co = target.func_code118 if 'env' in co.co_varnames[:co.co_argcount]:119 target(self.parent.env, *args)120 else:121 target(*args)122123124class JinjaDocTest(py.test.collect.Item):125126 def __init__(self, *args, **kwargs):127 realmod = kwargs.pop('realmod', False)128 super(JinjaDocTest, self).__init__(*args, **kwargs)129 self.realmod = realmod130131 def run(self):132 if self.realmod:133 mod = __import__(self.name, None, None, [''])134 else:135 mod = py.std.types.ModuleType(self.name)136 mod.__doc__ = self.obj137 mod.env = self.parent.env138 mod.MODULE = self.parent.obj139 self.execute(mod)140141 def execute(self, mod):142 failed, tot = py.compat.doctest.testmod(mod, verbose=True)143 if failed:144 py.test.fail('doctest %s: %s failed out of %s' % (145 self.fspath, failed, tot))146147148class JinjaDocTestModule(py.test.collect.Module):149150 def __init__(self, *args, **kwargs):151 super(JinjaDocTestModule, self).__init__(*args, **kwargs)152 self.doctest_modules = [153 'jinja2.environment', 'jinja2.compiler', 'jinja2.parser',154 'jinja2.lexer', 'jinja2.ext', 'jinja2.sandbox',155 'jinja2.filters', 'jinja2.tests', 'jinja2.utils',156 'jinja2.runtime'157 ]158159 def run(self):160 return self.doctest_modules161162 def join(self, name):163 return JinjaDocTest(name, parent=self, realmod=True)
modified:tests/test_debug.py+2 added-8 removed
9 unmodified lines
10"""11from jinja2 import Environment12from test_loaders import filesystem_loader1314import conftest15if conftest.NOSE:16 import sys17 MODULE = sys.modules[__name__]181914env = Environment(loader=filesystem_loader)151617def test_runtime_error():18 '''25>>> tmpl = MODULE.env.get_template('broken.html')19>>> tmpl = env.get_template('broken.html')20>>> tmpl.render(fail=lambda: 1 / 0)21Traceback (most recent call last):22 File "loaderres/templates/broken.html", line 2, in top-level template code23 {{ fail() }}
4 unmodified lines
282930def test_syntax_error():31 '''38>>> tmpl = MODULE.env.get_template('syntaxerror.html')32>>> tmpl = env.get_template('syntaxerror.html')33Traceback (most recent call last):34 ...35TemplateSyntaxError: unknown tag 'endif'36 File "loaderres/templates\\syntaxerror.html", line 4
15 unmodified lines
modified:tests/test_filters.py+39 added-44 removed
6 unmodified lines
7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Markup, Environment1011import conftest11env = Environment()121314CAPITALIZE = '''{{ "foo bar"|capitalize }}'''15CENTER = '''{{ "foo"|center(9) }}'''
55 unmodified lines
71FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''72SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''737475def test_capitalize(env):75def test_capitalize():76 tmpl = env.from_string(CAPITALIZE)77 assert tmpl.render() == 'Foo bar'787980def test_center(env):80def test_center():81 tmpl = env.from_string(CENTER)82 assert tmpl.render() == ' foo '838485def test_default(env):85def test_default():86 tmpl = env.from_string(DEFAULT)87 assert tmpl.render(given='yes') == 'no|False|no|yes'888990def test_dictsort(env):90def test_dictsort():91 tmpl = env.from_string(DICTSORT)92 out = tmpl.render(foo={"a": 0, "b": 1, "c": 2, "A": 3})93 assert out == ("[('a', 0), ('A', 3), ('b', 1), ('c', 2)]|"94 "[('A', 3), ('a', 0), ('b', 1), ('c', 2)]|"95 "[('a', 0), ('b', 1), ('c', 2), ('A', 3)]")969798def test_batch(env):98def 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']]")103104105def test_slice(env):105def 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']]")110111112def test_escape(env):112def test_escape():113 tmpl = env.from_string(ESCAPE)114 out = tmpl.render()115 assert out == '&lt;&#34;&gt;&amp;'116117118def test_striptags(env):118def 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'124125126def test_filesizeformat(env):126def 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 )133134135def test_first(env):135def test_first():136 tmpl = env.from_string(FIRST)137 out = tmpl.render(foo=range(10))138 assert out == '0'139140141def test_float(env):141def test_float():142 tmpl = env.from_string(FLOAT)143 out = tmpl.render()144 assert out == '42.0|0.0|32.32'145146147def test_format(env):147def test_format():148 tmpl = env.from_string(FORMAT)149 out = tmpl.render()150 assert out == 'a|b'151152153def test_indent(env):153def 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')159160161def test_int(env):161def test_int():162 tmpl = env.from_string(INT)163 out = tmpl.render()164 assert out == '42|0|32'165166167def test_join(env):167def test_join():168 tmpl = env.from_string(JOIN)169 out = tmpl.render()170 assert out == '1|2|3'171
1 unmodified line
173 tmpl = env2.from_string('{{ ["<foo>", "<span>foo</span>"|safe]|join }}')174 assert tmpl.render() == '&lt;foo&gt;<span>foo</span>'175176177def test_last(env):177def test_last():178 tmpl = env.from_string(LAST)179 out = tmpl.render(foo=range(10))180 assert out == '9'181182183def test_length(env):183def test_length():184 tmpl = env.from_string(LENGTH)185 out = tmpl.render()186 assert out == '11'187188189def test_lower(env):189def test_lower():190 tmpl = env.from_string(LOWER)191 out = tmpl.render()192 assert out == 'foo'193194195def test_pprint(env):195def test_pprint():196 from pprint import pformat197 tmpl = env.from_string(PPRINT)198 data = range(1000)199 assert tmpl.render(data=data) == pformat(data)200201202def test_random(env):202def 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 seq207208209def test_reverse(env):209def test_reverse():210 tmpl = env.from_string(REVERSE)211 assert tmpl.render() == 'raboof|[3, 2, 1]'212213214def test_string(env):214def test_string():215 tmpl = env.from_string(STRING)216 assert tmpl.render(foo=range(10)) == unicode(xrange(10))217218219def test_title(env):219def test_title():220 tmpl = env.from_string(TITLE)221 assert tmpl.render() == "Foo Bar"222223224def NOT_WORKING_test_truncate(env):224def test_truncate():225 tmpl = env.from_string(TRUNCATE)226 assert tmpl.render() == 'foo'227228229def test_truncate2(env):230 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'229230236def test_upper(env):231def test_upper():232 tmpl = env.from_string(UPPER)233 assert tmpl.render() == 'FOO'234235241def test_urlize(env):236def 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'240241247def test_wordcount(env):242def test_wordcount():243 tmpl = env.from_string(WORDCOUNT)244 assert tmpl.render() == '3'245246252def test_block(env):247def test_block():248 tmpl = env.from_string(BLOCK)249 assert tmpl.render() == '&lt;hehe&gt;'250251257def test_chaining(env):252def test_chaining():253 tmpl = env.from_string(CHAINING)254 assert tmpl.render() == '&lt;FOO&gt;'255256262def test_sum(env):257def test_sum():258 tmpl = env.from_string(SUM)259 assert tmpl.render() == '21'260261267def test_abs(env):262def test_abs():263 tmpl = env.from_string(ABS)264 return tmpl.render() == '1|1'265266272def test_round(env):267def test_round():268 tmpl = env.from_string(ROUND)269 return tmpl.render() == '3.0|2.0|2.1|3.0'270271277def test_xmlattr(env):272def test_xmlattr():273 tmpl = env.from_string(XMLATTR)274 out = tmpl.render().split()275 assert len(out) == 3276 assert 'foo="42"' in out277 assert 'bar="23"' in out278 assert 'blub:blub="&lt;?&gt;"' in out279280286def test_sort1(env):281def test_sort1():282 tmpl = env.from_string(SORT1)283 assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'284285291def test_groupby(env):286def 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 ]293294300def test_filtertag(env):295def test_filtertag():296 tmpl = env.from_string(FILTERTAG)297 assert tmpl.render() == 'fooBAR'298299
10 unmodified lines
310 tmpl = env.from_string('{{ string|replace("o", ">x<") }}')311 assert tmpl.render(string=Markup('foo')) == 'f&gt;x&lt;&gt;x&lt;'312313319def test_forceescape(env):314def test_forceescape():315 tmpl = env.from_string('{{ x|forceescape }}')316 assert tmpl.render(x=Markup('<div />')) == u'&lt;div /&gt;'317318
4 unmodified lines
323 tmpl = env.from_string('{{ "<div>foo</div>" }}')324 assert tmpl.render() == '&lt;div&gt;foo&lt;/div&gt;'325326332def test_sort2(env):327def test_sort2():328 assert env.from_string(SORT2).render() == "['Bar', 'blah', 'foo']"
modified:tests/test_forloop.py+26 added-27 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment10from jinja2.exceptions import UndefinedError, TemplateSyntaxError1111import conftest12if conftest.NOSE:13 from nose.tools import assert_raises as raises12from nose.tools import assert_raises14else:15 from py.test import raises1314env = Environment()151617SIMPLE = '''{% for item in seq %}{{ item }}{% endfor %}'''18ELSE = '''{% for item in seq %}XXX{% else %}...{% endfor %}'''19EMPTYBLOCKS = '''<{% for item in seq %}{% else %}{% endfor %}>'''20CONTEXTVARS = '''{% for item in seq %}\
26 unmodified lines
47LOOPUNASSIGNABLE = '''\48{% for loop in seq %}...{% endfor %}'''495052def test_simple(env):51def test_simple():52 tmpl = env.from_string(SIMPLE)53 assert tmpl.render(seq=range(10)) == '0123456789'545557def test_else(env):56def test_else():57 tmpl = env.from_string(ELSE)58 assert tmpl.render() == '...'596062def test_empty_blocks(env):61def test_empty_blocks():62 tmpl = env.from_string(EMPTYBLOCKS)63 assert tmpl.render() == '<>'646567def test_context_vars(env):66def 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('|')
8 unmodified lines
79 assert one_last == 'False' and two_last == 'True'80 assert one_length == two_length == '2'818284def test_cycling(env):83def test_cycling():84 tmpl = env.from_string(CYCLING)85 output = tmpl.render(seq=range(4), through=('<1>', '<2>'))86 assert output == '<1><2>' * 4878890def test_scope(env):89def test_scope():90 tmpl = env.from_string(SCOPE)91 output = tmpl.render(seq=range(10))92 assert not output939496def test_varlen(env):95def test_varlen():96 def inner():97 for item in range(5):98 yield item99 tmpl = env.from_string(VARLEN)100 output = tmpl.render(iter=inner())101 assert output == '01234'102103105def test_noniter(env):104def test_noniter():105 tmpl = env.from_string(NONITER)107 raises(TypeError, tmpl.render)106 assert_raises(TypeError, tmpl.render)107108110def test_recursive(env):109def 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]>]'116117119def test_looploop(env):118def test_looploop():119 tmpl = env.from_string(LOOPLOOP)120 assert tmpl.render(table=['ab', 'cd']) == '[1|1][1|2][2|1][2|2]'121122124def test_reversed_bug(env):123def 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'127128130def test_loop_errors(env):129def test_loop_errors():130 tmpl = env.from_string(LOOPERROR1)132 raises(UndefinedError, tmpl.render)131 assert_raises(UndefinedError, tmpl.render)132 tmpl = env.from_string(LOOPERROR2)133 assert tmpl.render() == ''134135137def test_loop_filter(env):136def 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]'141142144def test_loop_unassignable(env):145 raises(TemplateSyntaxError, env.from_string, LOOPUNASSIGNABLE)143def test_loop_unassignable():144 assert_raises(TemplateSyntaxError, env.from_string, LOOPUNASSIGNABLE)145146148def test_scoped_special_var(env):147def 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]'151152154def test_scoped_loop_var(env):153def 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'160161163def test_recursive_empty_loop_iter(env):162def test_recursive_empty_loop_iter():163 t = env.from_string('''164 {%- for item in foo recursive -%}{%- endfor -%}165 ''')166 assert t.render(dict(foo=[])) == ''167168170def test_call_in_loop(env):169def test_call_in_loop():170 t = env.from_string('''171 {%- macro do_something() -%}172 [{{ caller() }}]173 {%- endmacro %}
6 unmodified lines
180 ''')181 assert t.render() == '[1][2][3]'182183185def test_scoping_bug(env):184def test_scoping_bug():185 t = env.from_string('''186 {%- for item in foo %}...{{ item }}...{% endfor %}187 {%- macro item(a) %}...{{ a }}...{% endmacro %}188 {{- item(2) -}}
2 unmodified lines
modified:tests/test_heavy.py+4 added-4 removed
8 unmodified lines
910 :copyright: Copyright 2009 by the Jinja Team.11 :license: BSD.12"""13from jinja2 import Environment14env = Environment()1514import conftest161617def test_assigned_scoping(env):17def test_assigned_scoping():18 t = env.from_string('''19 {%- for item in (1, 2, 3, 4) -%}20 [{{ item }}]21 {%- endfor %}
19 unmodified lines
41 ''')42 assert t.render() == '[1][2][3][4]42'434445def test_closure_scoping(env):45def 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 %}
24 unmodified lines
modified:tests/test_i18n.py+3 added-7 removed
7 unmodified lines
8"""9from jinja2 import Environment, DictLoader, contextfunction10from jinja2.exceptions import TemplateAssertionError1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises12from nose.tools import assert_raises15else:16 from py.test import raises1314templates = {15 'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'16 '{% block body %}{% endblock %}',
55 unmodified lines
72def 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'80 raises(TemplateAssertionError, i18n_env.from_string,81 '{% trans foo %}...{% pluralize bar %}...{% endtrans %}')76 assert_raises(TemplateAssertionError, i18n_env.from_string,77 '{% trans foo %}...{% pluralize bar %}...{% endtrans %}')787980def test_trans_stringformatting():81 tmpl = i18n_env.get_template('stringformat.html')
16 unmodified lines
modified:tests/test_ifcondition.py+8 added-7 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910import conftest10from jinja2 import Environment11env = Environment()121314SIMPLE = '''{% if true %}...{% endif %}'''15ELIF = '''{% if false %}XXX{% elif true %}...{% else %}XXX{% endif %}'''16ELSE = '''{% if false %}XXX{% else %}...{% endif %}'''17EMPTY = '''[{% if true %}{% else %}{% endif %}]'''181919def test_simple(env):20def test_simple():21 tmpl = env.from_string(SIMPLE)22 assert tmpl.render() == '...'232424def test_elif(env):25def test_elif():26 tmpl = env.from_string(ELIF)27 assert tmpl.render() == '...'282929def test_else(env):30def test_else():31 tmpl = env.from_string(ELSE)32 assert tmpl.render() == '...'333434def test_empty(env):35def test_empty():36 tmpl = env.from_string(EMPTY)37 assert tmpl.render() == '[]'383939def test_complete(env):40def 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'444545def test_no_scope(env):46def 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'
modified:tests/test_imports.py+2 added-6 removed
7 unmodified lines
8"""9from jinja2 import Environment, DictLoader10from jinja2.exceptions import TemplateNotFound1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises12from nose.tools import assert_raises15else:16 from py.test import raises131415test_env = Environment(loader=DictLoader(dict(16 module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',
28 unmodified lines
454647def test_include_ignoring_missing():48 t = test_env.from_string('{% include "missing" %}')53 raises(TemplateNotFound, t.render)49 assert_raises(TemplateNotFound, t.render)50 for extra in '', 'with context', 'without context':51 t = test_env.from_string('{% include "missing" ignore missing ' +52 extra + ' %}')53 assert t.render() == ''
44 unmodified lines
modified:tests/test_inheritance.py+16 added-10 removed
8 unmodified lines
910from jinja2 import Environment, DictLoader11from jinja2.exceptions import TemplateSyntaxError1213import conftest14conftest.GlobalLoader.scope = globals()131614LAYOUTTEMPLATE = '''\15|{% block block1 %}block 1 from layout{% endblock %}16|{% block block2 %}block 2 from layout{% endblock %}17|{% block block3 %}
30 unmodified lines
48 {% endif %}49{% endblock %}50'''5152env = Environment(loader=DictLoader({53 'layout': LAYOUTTEMPLATE,54 'level1': LEVEL1TEMPLATE,55 'level2': LEVEL2TEMPLATE,56 'level3': LEVEL3TEMPLATE,57 'level4': LEVEL4TEMPLATE,58 'working': WORKINGTEMPLATE59}), trim_blocks=True)6055def test_layout(env):61def test_layout():62 tmpl = env.get_template('layout')63 assert tmpl.render() == ('|block 1 from layout|block 2 from '64 'layout|nested block 4 from layout|')656661def test_level1(env):67def test_level1():68 tmpl = env.get_template('level1')69 assert tmpl.render() == ('|block 1 from level1|block 2 from '70 'layout|nested block 4 from layout|')717267def test_level2(env):73def test_level2():74 tmpl = env.get_template('level2')75 assert tmpl.render() == ('|block 1 from level1|nested block 5 from '76 'level2|nested block 4 from layout|')777873def test_level3(env):79def test_level3():80 tmpl = env.get_template('level3')81 assert tmpl.render() == ('|block 1 from level1|block 5 from level3|'82 'block 4 from level3|')838479def test_level4(env):85def test_level4():86 tmpl = env.get_template('level4')87 assert tmpl.render() == ('|block 1 from level1|block 5 from '88 'level3|block 3 from level4|')89
11 unmodified lines
101 tmpl = env.get_template('c')102 assert tmpl.render() == '--INTRO--|BEFORE|[(INNER)]|AFTER'10310499def test_working(env):105def test_working():106 tmpl = env.get_template('working')107108103def test_reuse_blocks(env):109def test_reuse_blocks():110 tmpl = env.from_string('{{ self.foo() }}|{% block foo %}42{% endblock %}|{{ self.foo() }}')111 assert tmpl.render() == '42|42|42'112113
84 unmodified lines
modified:tests/test_lexer.py+6 added-5 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment1010import conftest11env = Environment()121314RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{% endraw %}'15BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''
5 unmodified lines
21</ul>'''22BYTEFALLBACK = u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}'''232424def test_raw(env):25def test_raw():26 tmpl = env.from_string(RAW)27 assert tmpl.render() == 'foo|{{ bar }}|{% baz %}'2829
11 unmodified lines
41 assert tmpl.render(seq=range(3)) == ("<ul>\n <li>0</li>\n "42 "<li>1</li>\n <li>2</li>\n</ul>")434444def test_string_escapes(env):45def test_string_escapes():46 for char in u'\0', u'\u2668', u'\xe4', u'\t', u'\r', u'\n':47 tmpl = env.from_string('{{ %s }}' % repr(char)[1:])48 assert tmpl.render() == char49 assert env.from_string('{{ "\N{HOT SPRINGS}" }}').render() == u'\u2668'505151def test_bytefallback(env):52def test_bytefallback():53 tmpl = env.from_string(BYTEFALLBACK)54 assert tmpl.render() == u"'foo'|u'b\\xe4r'"555656def test_operators(env):57def test_operators():58 from jinja2.lexer import operators59 for test, expect in operators.iteritems():60 if test in '([{}])':61 continue
12 unmodified lines
modified:tests/test_loaders.py+8 added-12 removed
11 unmodified lines
12from jinja2 import Environment, loaders13from jinja2.loaders import split_template_path14from jinja2.exceptions import TemplateNotFound1516import conftest17if conftest.NOSE:18 from nose.tools import assert_raises as raises16from nose.tools import assert_raises19else:20 from py.test import raises171819dict_loader = loaders.DictLoader({20 'justdict.html': 'FOO'
11 unmodified lines
32def test_dict_loader():33 env = Environment(loader=dict_loader)34 tmpl = env.get_template('justdict.html')35 assert tmpl.render().strip() == 'FOO'40 raises(TemplateNotFound, env.get_template, 'missing.html')36 assert_raises(TemplateNotFound, env.get_template, 'missing.html')373839def test_package_loader():40 env = Environment(loader=package_loader)41 tmpl = env.get_template('test.html')42 assert tmpl.render().strip() == 'BAR'47 raises(TemplateNotFound, env.get_template, 'missing.html')43 assert_raises(TemplateNotFound, env.get_template, 'missing.html')444546def test_filesystem_loader():47 env = Environment(loader=filesystem_loader)48 tmpl = env.get_template('test.html')49 assert tmpl.render().strip() == 'BAR'50 tmpl = env.get_template('foo/test.html')51 assert tmpl.render().strip() == 'FOO'56 raises(TemplateNotFound, env.get_template, 'missing.html')52 assert_raises(TemplateNotFound, env.get_template, 'missing.html')535455def test_choice_loader():56 env = Environment(loader=choice_loader)57 tmpl = env.get_template('justdict.html')58 assert tmpl.render().strip() == 'FOO'59 tmpl = env.get_template('test.html')60 assert tmpl.render().strip() == 'BAR'65 raises(TemplateNotFound, env.get_template, 'missing.html')61 assert_raises(TemplateNotFound, env.get_template, 'missing.html')626364def test_function_loader():65 env = Environment(loader=function_loader)66 tmpl = env.get_template('justfunction.html')67 assert tmpl.render().strip() == 'FOO'72 raises(TemplateNotFound, env.get_template, 'missing.html')68 assert_raises(TemplateNotFound, env.get_template, 'missing.html')697071def test_prefix_loader():72 env = Environment(loader=prefix_loader)73 tmpl = env.get_template('a/test.html')74 assert tmpl.render().strip() == 'BAR'75 tmpl = env.get_template('b/justdict.html')76 assert tmpl.render().strip() == 'FOO'81 raises(TemplateNotFound, env.get_template, 'missing')77 assert_raises(TemplateNotFound, env.get_template, 'missing')787980def test_caching():81 changed = False
25 unmodified lines
107108def test_split_template_path():109 assert split_template_path('foo/bar') == ['foo', 'bar']110 assert split_template_path('./foo/bar') == ['foo', 'bar']115 raises(TemplateNotFound, split_template_path, '../foo')111 assert_raises(TemplateNotFound, split_template_path, '../foo')
modified:tests/test_macros.py+13 added-11 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910import conftest11conftest.GlobalLoader.scope = globals()10from jinja2 import Environment, DictLoader1112env = Environment(trim_blocks=True)131415SIMPLE = '''\16{% macro say_hello(name) %}Hello {{ name }}!{% endmacro %}17{{ say_hello('Peter') }}\18'''
33 unmodified lines
5253INCLUDETEMPLATE = '''{% macro test(foo) %}[{{ foo }}]{% endmacro %}'''545555def test_simple(env):56def test_simple():57 tmpl = env.from_string(SIMPLE)58 assert tmpl.render() == 'Hello Peter!'596060def test_scoping(env):61def test_scoping():62 tmpl = env.from_string(SCOPING)63 assert tmpl.render() == 'foo|bar'646565def test_arguments(env):66def test_arguments():67 tmpl = env.from_string(ARGUMENTS)68 assert tmpl.render() == '||c|d|a||c|d|a|b|c|d|1|2|3|d'697070def test_varargs(env):71def test_varargs():72 tmpl = env.from_string(VARARGS)73 assert tmpl.render() == '1|2|3'747575def test_simple_call(env):76def test_simple_call():77 tmpl = env.from_string(SIMPLECALL)78 assert tmpl.render() == '[[data]]'798080def test_complex_call(env):81def test_complex_call():82 tmpl = env.from_string(COMPLEXCALL)83 assert tmpl.render() == '[[data]]'848585def test_caller_undefined(env):86def test_caller_undefined():87 tmpl = env.from_string(CALLERUNDEFINED)88 assert tmpl.render() == 'True'899090def test_include(env):91def test_include():92 env = Environment(loader=DictLoader({'include': INCLUDETEMPLATE}))93 tmpl = env.from_string('{% from "include" import test %}{{ test("foo") }}')94 assert tmpl.render() == '[foo]'959695def test_macro_api(env):97def test_macro_api():98 tmpl = env.from_string('{% macro foo(a, b) %}{% endmacro %}'99 '{% macro bar() %}{{ varargs }}{{ kwargs }}{% endmacro %}'100 '{% macro baz() %}{{ caller() }}{% endmacro %}')101 assert tmpl.module.foo.arguments == ('a', 'b')
11 unmodified lines
modified:tests/test_old_bugs.py+8 added-10 removed
8 unmodified lines
9 :license: BSD.10"""11from jinja2 import Environment, DictLoader, TemplateSyntaxError1213import conftest14if conftest.NOSE:15 from nose.tools import assert_raises as raises16else:17 from py.test import raises13env = Environment()1415from nose.tools import assert_raises161718def test_keyword_folding():19 env = Environment()20 env.filters['testing'] = lambda value, some: value + some21 assert env.from_string("{{ 'test'|testing(some='stuff') }}") \
11 unmodified lines
33 assert t.render(expr=False) == '[[title]](1)(2)(3)'34 assert t.render(expr=True) == '((title))'353639def test_urlize_filter_escaping(env):37def test_urlize_filter_escaping():38 tmpl = env.from_string('{{ "http://www.example.org/<foo"|urlize }}')39 assert tmpl.render() == '<a href="http://www.example.org/&lt;foo">http://www.example.org/&lt;foo</a>'404144def test_loop_call_loop(env):42def test_loop_call_loop():43 tmpl = env.from_string('''4445 {% macro test() %}46 {{ caller() }}
13 unmodified lines
606162def test_weird_inline_comment():63 env = Environment(line_statement_prefix='%')66 raises(TemplateSyntaxError, env.from_string,67 '% for item in seq {# missing #}\n...% endfor')64 assert_raises(TemplateSyntaxError, env.from_string,65 '% for item in seq {# missing #}\n...% endfor')666770def test_old_macro_loop_scoping_bug(env):68def test_old_macro_loop_scoping_bug():69 tmpl = env.from_string('{% for i in (1, 2) %}{{ i }}{% endfor %}'70 '{% macro i() %}3{% endmacro %}{{ i() }}')71 assert tmpl.render() == '123'
modified:tests/test_parser.py+3 added-3 removed
6 unmodified lines
7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment1011import conftest11env = Environment()121314PHP_SYNTAX = '''\15<!-- I'm a comment, I'm not interesting -->\
67 unmodified lines
83 tmpl = env.from_string(COMMENT_SYNTAX)84 assert tmpl.render(seq=range(5)) == '01234'858687def test_balancing(env):87def test_balancing():88 tmpl = env.from_string(BALANCING)89 assert tmpl.render() == 'bar'909192def test_start_comment(env):92def test_start_comment():93 tmpl = env.from_string(STARTCOMMENT)94 assert tmpl.render().strip() == 'foo'9596
20 unmodified lines
modified:tests/test_security.py+12 added-18 removed
11 unmodified lines
12from jinja2 import Markup, escape13from jinja2.exceptions import SecurityError, TemplateSyntaxError141516import conftest17if conftest.NOSE:18 from nose.tools import assert_raises as raises16from nose.tools import assert_raises19 import sys20 MODULE = sys.modules[__name__]21else:22 from py.test import raises1718class PrivateStuff(object):1920 def bar(self):
16 unmodified lines
373839def test_unsafe():40 '''47>>> env = MODULE.SandboxedEnvironment()48>>> env.from_string("{{ foo.foo() }}").render(foo=MODULE.PrivateStuff())41>>> env = SandboxedEnvironment()42>>> env.from_string("{{ foo.foo() }}").render(foo=PrivateStuff())43Traceback (most recent call last):44 ...45SecurityError: <bound method PrivateStuff.foo of PrivateStuff> is not safely callable52>>> env.from_string("{{ foo.bar() }}").render(foo=MODULE.PrivateStuff())46>>> env.from_string("{{ foo.bar() }}").render(foo=PrivateStuff())47u'23'4855>>> env.from_string("{{ foo._foo() }}").render(foo=MODULE.PublicStuff())49>>> env.from_string("{{ foo._foo() }}").render(foo=PublicStuff())50Traceback (most recent call last):51 ...52SecurityError: access to attribute '_foo' of 'PublicStuff' object is unsafe.59>>> env.from_string("{{ foo.bar() }}").render(foo=MODULE.PublicStuff())53>>> env.from_string("{{ foo.bar() }}").render(foo=PublicStuff())54u'23'5556>>> env.from_string("{{ foo.__class__ }}").render(foo=42)57u''
7 unmodified lines
656667def test_restricted():68 env = SandboxedEnvironment()75 raises(TemplateSyntaxError, env.from_string,76 "{% for item.attribute in seq %}...{% endfor %}")77 raises(TemplateSyntaxError, env.from_string,78 "{% for foo, bar.baz in seq %}...{% endfor %}")69 assert_raises(TemplateSyntaxError, env.from_string,70 "{% for item.attribute in seq %}...{% endfor %}")71 assert_raises(TemplateSyntaxError, env.from_string,72 "{% for foo, bar.baz in seq %}...{% endfor %}")737475def test_immutable_environment():76 '''83>>> env = MODULE.ImmutableSandboxedEnvironment()77>>> env = ImmutableSandboxedEnvironment()78>>> env.from_string('{{ [].append(23) }}').render()79Traceback (most recent call last):80 ...81SecurityError: access to attribute 'append' of 'list' object is unsafe.
55 unmodified lines
137138def test_attr_filter():139 env = SandboxedEnvironment()140 tmpl = env.from_string('{{ 42|attr("__class__")|attr("__subclasses__")() }}')147 raises(SecurityError, tmpl.render)141 assert_raises(SecurityError, tmpl.render)
modified:tests/test_streaming.py+2 added-3 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910import conftest11if conftest.NOSE:12 env = conftest.simple_env10from jinja2 import Environment11env = Environment()121314def test_basic_streaming():15 r"""
42 unmodified lines
modified:tests/test_syntax.py+34 added-37 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment, DictLoader9from jinja2 import Environment10from jinja2.exceptions import TemplateSyntaxError, UndefinedError1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises12from nose.tools import assert_raises15else:16 from py.test import raises1314env = Environment()151617CALL = '''{{ foo('a', c='d', e='f', *['b'], **{'g': 'h'}) }}'''18SLICING = '''{{ [1, 2, 3][:] }}|{{ [1, 2, 3][::-1] }}'''19ATTR = '''{{ foo.bar }}|{{ foo['bar'] }}'''20SUBSCRIPT = '''{{ foo[0] }}|{{ foo[-1] }}'''
23 unmodified lines
44TRAILINGCOMMA = '''{{ (1, 2,) }}|{{ [1, 2,] }}|{{ {1: 2,} }}'''454647def test_call():50 from jinja2 import Environment48 env = Environment()49 env.globals['foo'] = lambda a, b, c, e, g: a + b + c + e + g50 tmpl = env.from_string(CALL)51 assert tmpl.render() == 'abdfh'525357def test_slicing(env):54def test_slicing():55 tmpl = env.from_string(SLICING)56 assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'575862def test_attr(env):59def test_attr():60 tmpl = env.from_string(ATTR)61 assert tmpl.render(foo={'bar': 42}) == '42|42'626367def test_subscript(env):64def test_subscript():65 tmpl = env.from_string(SUBSCRIPT)66 assert tmpl.render(foo=[0, 1, 2]) == '0|2'676872def test_tuple(env):69def test_tuple():70 tmpl = env.from_string(TUPLE)71 assert tmpl.render() == '()|(1,)|(1, 2)'727377def test_math(env):74def test_math():75 tmpl = env.from_string(MATH)76 assert tmpl.render() == '1.5|8'777882def test_div(env):79def test_div():80 tmpl = env.from_string(DIV)81 assert tmpl.render() == '1|1.5|1'828387def test_unary(env):84def test_unary():85 tmpl = env.from_string(UNARY)86 assert tmpl.render() == '3|-3'878892def test_concat(env):89def test_concat():90 tmpl = env.from_string(CONCAT)91 assert tmpl.render() == '[1, 2]foo'929397def test_compare(env):94def test_compare():95 tmpl = env.from_string(COMPARE)96 assert tmpl.render() == 'True|True|True|True|True'9798102def test_inop(env):99def test_inop():100 tmpl = env.from_string(INOP)101 assert tmpl.render() == 'True|False'102103107def test_literals(env):104def test_literals():105 tmpl = env.from_string(LITERALS)106 assert tmpl.render().lower() == '[]|{}|()'107108112def test_bool(env):109def test_bool():110 tmpl = env.from_string(BOOL)111 assert tmpl.render() == 'False|True|True'112113117def test_grouping(env):114def test_grouping():115 tmpl = env.from_string(GROUPING)116 assert tmpl.render() == 'False'117118122def test_django_attr(env):119def test_django_attr():120 tmpl = env.from_string(DJANGOATTR)121 assert tmpl.render() == '1|1'122123127def test_conditional_expression(env):124def test_conditional_expression():125 tmpl = env.from_string(CONDEXPR)126 assert tmpl.render() == '0'127128132def test_short_conditional_expression(env):129def test_short_conditional_expression():130 tmpl = env.from_string('<{{ 1 if false }}>')131 assert tmpl.render() == '<>'132133 tmpl = env.from_string('<{{ (1 if false).bar }}>')137 raises(UndefinedError, tmpl.render)134 assert_raises(UndefinedError, tmpl.render)135136140def test_filter_priority(env):137def test_filter_priority():138 tmpl = env.from_string(FILTERPRIORITY)139 assert tmpl.render() == 'FOOBAR'140141145def test_function_calls(env):142def test_function_calls():143 tests = [144 (True, '*foo, bar'),145 (True, '*foo, *bar'),146 (True, '*foo, bar=42'),
6 unmodified lines
153 (False, '*foo, **bar')154 ]155 for should_fail, sig in tests:156 if should_fail:160 raises(TemplateSyntaxError, env.from_string, '{{ foo(%s) }}' % sig)157 assert_raises(TemplateSyntaxError, env.from_string, '{{ foo(%s) }}' % sig)158 else:159 env.from_string('foo(%s)' % sig)160161165def test_tuple_expr(env):162def test_tuple_expr():163 for tmpl in TUPLETEMPLATES:164 print tmpl165 assert env.from_string(tmpl)166167171def test_trailing_comma(env):168def test_trailing_comma():169 tmpl = env.from_string(TRAILINGCOMMA)170 assert tmpl.render().lower() == '(1, 2)|[1, 2]|{1: 2}'171172176def test_block_end_name(env):173def test_block_end_name():174 env.from_string('{% block foo %}...{% endblock foo %}')178 raises(TemplateSyntaxError, env.from_string, '{% block x %}{% endblock y %}')175 assert_raises(TemplateSyntaxError, env.from_string, '{% block x %}{% endblock y %}')176177181def test_contant_casing(env):178def test_contant_casing():179 for const in True, False, None:180 tmpl = env.from_string('{{ %s }}|{{ %s }}|{{ %s }}' % (181 str(const), str(const).lower(), str(const).upper()182 ))183 assert tmpl.render() == '%s|%s|' % (const, const)184185189def test_test_chaining(env):190 raises(TemplateSyntaxError, env.from_string, '{{ foo is string is sequence }}')186def test_test_chaining():187 assert_raises(TemplateSyntaxError, env.from_string, '{{ foo is string is sequence }}')188 env.from_string('{{ 42 is string or 42 is number }}').render() == 'True'189190194def test_string_concatenation(env):191def test_string_concatenation():192 tmpl = env.from_string('{{ "foo" "bar" "baz" }}')193 assert tmpl.render() == 'foobarbaz'194195199def test_notin(env):196def test_notin():197 bar = xrange(100)198 tmpl = env.from_string('''{{ not 42 in bar }}''')199 assert tmpl.render(bar=bar) == unicode(not 42 in bar)200201205def test_implicit_subscribed_tuple(env):202def test_implicit_subscribed_tuple():203 class Foo(object):204 def __getitem__(self, x):205 return x206 t = env.from_string('{{ foo[1, 2] }}')
1 unmodified line
modified:tests/test_tests.py+11 added-12 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment, Markup10env = Environment()1111import conftest121313DEFINED = '''{{ missing is defined }}|{{ true is defined }}'''14EVEN = '''{{ 1 is even }}|{{ 2 is even }}'''15LOWER = '''{{ "foo" is lower }}|{{ "FOO" is lower }}'''16ODD = '''{{ 1 is odd }}|{{ 2 is odd }}'''
17 unmodified lines
34{{ 42 is callable }}35{{ range(5) is iterable }}'''363739def test_defined(env):38def test_defined():39 tmpl = env.from_string(DEFINED)40 assert tmpl.render() == 'False|True'414244def test_even(env):43def test_even():44 tmpl = env.from_string(EVEN)45 assert tmpl.render() == 'False|True'464749def test_odd(env):48def test_odd():49 tmpl = env.from_string(ODD)50 assert tmpl.render() == 'True|False'515254def test_lower(env):53def test_lower():54 tmpl = env.from_string(LOWER)55 assert tmpl.render() == 'True|False'565759def test_typechecks(env):58def test_typechecks():59 tmpl = env.from_string(TYPECHECKS)60 assert tmpl.render() == ''616264def test_sequence(env):63def test_sequence():64 tmpl = env.from_string(SEQUENCE)65 assert tmpl.render() == 'True|True|False'666769def test_upper(env):68def test_upper():69 tmpl = env.from_string(UPPER)70 assert tmpl.render() == 'True|False'717274def test_sameas(env):73def test_sameas():74 tmpl = env.from_string(SAMEAS)75 assert tmpl.render(foo=False) == 'True|False'767779def test_typechecks(env):78def test_typechecks():79 tmpl = env.from_string(TYPECHECKS)80 assert tmpl.render() == (81 'False\nTrue\nFalse\nTrue\nTrue\nFalse\n'82 'True\nTrue\nTrue\nTrue\nFalse\nTrue'83 )848587def test_no_paren_for_arg1(env):86def test_no_paren_for_arg1():87 tmpl = env.from_string(NOPARENFORARG1)88 assert tmpl.render(foo=None) == 'True'8990
4 unmodified lines
modified:tests/test_undefined.py+2 added-6 removed
7 unmodified lines
8"""9from jinja2 import Template10from jinja2.exceptions import UndefinedError1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises12from nose.tools import assert_raises15else:16 from py.test import raises131415def test_default_undefined():16 '''
65 unmodified lines
828384def test_indexing_gives_undefined():85 t = Template("{{ var[42].foo }}")90 raises(UndefinedError, t.render, var=0)86 assert_raises(UndefinedError, t.render, var=0)
modified:tests/test_various.py+11 added-15 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9import gc10from jinja2 import escape, is_undefined10from jinja2 import escape, is_undefined, Environment11from jinja2.utils import Cycler12from jinja2.exceptions import TemplateSyntaxError1314import conftest15if conftest.NOSE:16 from nose.tools import assert_raises as raises14from nose.tools import assert_raises17else:18 from py.test import raises1516env = Environment()171819UNPACKING = '''{% for a, b, c in [[1, 2, 3]] %}{{ a }}|{{ b }}|{{ c }}{% endfor %}'''20RAW = '''{% raw %}{{ FOO }} and {% BAR %}{% endraw %}'''21CONST = '''{{ true }}|{{ false }}|{{ none }}|\22{{ none is defined }}|{{ missing is defined }}'''
3 unmodified lines
26CONSTASS1 = '''{% set true = 42 %}'''27CONSTASS2 = '''{% for none in seq %}{% endfor %}'''282932def test_unpacking(env):30def test_unpacking():31 tmpl = env.from_string(UNPACKING)32 assert tmpl.render() == '1|2|3'333437def test_raw(env):35def test_raw():36 tmpl = env.from_string(RAW)37 assert tmpl.render() == '{{ FOO }} and {% BAR %}'383942def test_const(env):40def test_const():41 tmpl = env.from_string(CONST)42 assert tmpl.render() == 'True|False|None|True|False'434447def test_const_assign(env):45def test_const_assign():46 for tmpl in CONSTASS1, CONSTASS2:49 raises(TemplateSyntaxError, env.from_string, tmpl)47 assert_raises(TemplateSyntaxError, env.from_string, tmpl)484952def test_localset(env):50def test_localset():51 tmpl = env.from_string(LOCALSET)52 assert tmpl.render() == '0'5354
9 unmodified lines
64 assert len(counts) == 1, 'ouch, c extension seems to leak objects'656667def test_item_and_attribute():70 from jinja2 import Environment68 from jinja2.sandbox import SandboxedEnvironment6970 for env in Environment(), SandboxedEnvironment():71 tmpl = env.from_string('{{ foo.items() }}')
4 unmodified lines
76 assert tmpl.render(foo={'items': 42}) == '42'777879def test_finalizer():83 from jinja2 import Environment80 def finalize_none_empty(value):81 if value is None:82 value = u''83 return value
15 unmodified lines
99 c.reset()100 assert c.current == 1101102107def test_expressions(env):103def test_expressions():104 expr = env.compile_expression("foo")105 assert expr() is None106 assert expr(foo=42) == 42107 expr2 = env.compile_expression("foo", undefined_to_none=False)
4 unmodified lines
deleted:fabfile.py-40 removed
1# -*- coding: utf-8 -*-2"""3 Jinja fabfile4 ~~~~~~~~~~~~~56 Shortcuts for various tasks.78 :copyright: Copyright 2008 by Armin Ronacher.9 :license: BSD.10"""111213def test():14 """Run the testsuite."""15 local("cd tests; py.test")161718def pylint():19 """Run pylint."""20 local("pylint --rcfile scripts/pylintrc jinja")212223def release(**kwargs):24 """Release, tag and upload Jinja2 to the Cheeseshop."""25 import re26 _version_re = re.compile(r'VERSION\s*=\s["\'](.*?)["\']')27 f = file("setup.py")28 try:29 for line in f:30 match = _version_re.match(line)31 if match is not None:32 version = match.group(1)33 break34 else:35 raise RuntimeError('no version def in setup.py :-/')36 finally:37 f.close()3839 local('hg tag -m "%s" "%s"' % ('tagged %r' % version, version))40 local('python setup.py release sdist upload')