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
Provenance
- Commit
42979eb- Tree
043427c- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
1b43b58
21 files changed+210 added−448 removed
deleted:tests/conftest.py-163 removed
1-# -*- coding: utf-8 -*-2-"""3- conftest4- ~~~~~~~~5-6- Configure py.test for support stuff.7-8- :copyright: (c) 2009 by the Jinja Team.9- :license: BSD, see LICENSE for more details.10-"""11-12-import os13-import sys14-sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))15-16-import py17-from jinja2 import Environment18-from jinja2.loaders import BaseLoader19-from jinja2.exceptions import TemplateNotFound20-21-22-NOSE = 'nose' in sys.modules23-if NOSE:24- import inspect25- from nose import case26-27- 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 = runTest33-34-35-try: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".40-41- import coverage, atexit42-43- IGNORED_MODULES = ['jinja2._speedups', 'jinja2.defaults',44- 'jinja2.translators']45-46- 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)56-57- def callback(option, opt_str, value, parser):58- atexit.register(report_coverage)59- coverage.erase()60- coverage.start()61-62- 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!)'))65-66-except ImportError:67- coverage = None68-69-70-class GlobalLoader(BaseLoader):71- # Should be overwritten by importing module (test file) in order to find TEMPLATE vars72- scope = globals()73-74- def get_source(self, environment, name):75- try:76- return self.scope[name.upper() + 'TEMPLATE'], None, None77- except KeyError:78- raise TemplateNotFound(name)79-80-81-loader = GlobalLoader()82-simple_env = Environment(trim_blocks=True, loader=loader, cache_size=0)83-84-85-class Directory(py.test.collect.Directory):86-87- def run(self):88- rv = super(Directory, self).run()89- if self.fspath.basename == 'tests':90- rv.append('doctests')91- return rv92-93- def join(self, name):94- if name == 'doctests':95- return JinjaDocTestModule(name, parent=self)96- return super(Directory, self).join(name)97-98-99-class Module(py.test.collect.Module):100-101- def __init__(self, *args, **kwargs):102- self.env = simple_env103- super(Module, self).__init__(*args, **kwargs)104-105- 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)111-112-113-class JinjaTestFunction(py.test.collect.Function):114-115- 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)122-123-124-class JinjaDocTest(py.test.collect.Item):125-126- def __init__(self, *args, **kwargs):127- realmod = kwargs.pop('realmod', False)128- super(JinjaDocTest, self).__init__(*args, **kwargs)129- self.realmod = realmod130-131- 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)140-141- 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))146-147-148-class JinjaDocTestModule(py.test.collect.Module):149-150- 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- ]158-159- def run(self):160- return self.doctest_modules161-162- def join(self, name):163- return JinjaDocTest(name, parent=self, realmod=True)modified:tests/test_debug.py+2 added-8 removed
9 unmodified lines10 """11 from jinja2 import Environment12 from test_loaders import filesystem_loader13 14-import conftest15-if conftest.NOSE:16- import sys17- MODULE = sys.modules[__name__]18-19-14 env = Environment(loader=filesystem_loader)15 16 17 def 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)21 Traceback (most recent call last):22 File "loaderres/templates/broken.html", line 2, in top-level template code23 {{ fail() }}4 unmodified lines28 29 30 def test_syntax_error():31 '''38->>> tmpl = MODULE.env.get_template('syntaxerror.html')32+>>> tmpl = env.get_template('syntaxerror.html')33 Traceback (most recent call last):34 ...35 TemplateSyntaxError: unknown tag 'endif'36 File "loaderres/templates\\syntaxerror.html", line 415 unmodified linesmodified:tests/test_filters.py+39 added-44 removed
6 unmodified lines7 :license: BSD, see LICENSE for more details.8 """9 from jinja2 import Markup, Environment10 11-import conftest11+env = Environment()12 13 14 CAPITALIZE = '''{{ "foo bar"|capitalize }}'''15 CENTER = '''{{ "foo"|center(9) }}'''55 unmodified lines71 FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''72 SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''73 74 75-def test_capitalize(env):75+def test_capitalize():76 tmpl = env.from_string(CAPITALIZE)77 assert tmpl.render() == 'Foo bar'78 79 80-def test_center(env):80+def test_center():81 tmpl = env.from_string(CENTER)82 assert tmpl.render() == ' foo '83 84 85-def test_default(env):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(env):90+def 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)]")96 97 98-def test_batch(env):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(env):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(env):112+def test_escape():113 tmpl = env.from_string(ESCAPE)114 out = tmpl.render()115 assert out == '<">&'116 117 118-def test_striptags(env):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(env):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(env):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(env):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(env):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(env):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(env):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(env):167+def test_join():168 tmpl = env.from_string(JOIN)169 out = tmpl.render()170 assert out == '1|2|3'171 1 unmodified line173 tmpl = env2.from_string('{{ ["<foo>", "<span>foo</span>"|safe]|join }}')174 assert tmpl.render() == '<foo><span>foo</span>'175 176 177-def test_last(env):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(env):183+def test_length():184 tmpl = env.from_string(LENGTH)185 out = tmpl.render()186 assert out == '11'187 188 189-def test_lower(env):189+def test_lower():190 tmpl = env.from_string(LOWER)191 out = tmpl.render()192 assert out == 'foo'193 194 195-def test_pprint(env):195+def test_pprint():196 from pprint import pformat197 tmpl = env.from_string(PPRINT)198 data = range(1000)199 assert tmpl.render(data=data) == pformat(data)200 201 202-def test_random(env):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 seq207 208 209-def test_reverse(env):209+def test_reverse():210 tmpl = env.from_string(REVERSE)211 assert tmpl.render() == 'raboof|[3, 2, 1]'212 213 214-def test_string(env):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(env):219+def test_title():220 tmpl = env.from_string(TITLE)221 assert tmpl.render() == "Foo Bar"222 223 224-def NOT_WORKING_test_truncate(env):224+def test_truncate():225 tmpl = env.from_string(TRUNCATE)226- assert tmpl.render() == 'foo'227-228-229-def 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'229 230 236-def test_upper(env):231+def test_upper():232 tmpl = env.from_string(UPPER)233 assert tmpl.render() == 'FOO'234 235 241-def test_urlize(env):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 247-def test_wordcount(env):242+def test_wordcount():243 tmpl = env.from_string(WORDCOUNT)244 assert tmpl.render() == '3'245 246 252-def test_block(env):247+def test_block():248 tmpl = env.from_string(BLOCK)249 assert tmpl.render() == '<hehe>'250 251 257-def test_chaining(env):252+def test_chaining():253 tmpl = env.from_string(CHAINING)254 assert tmpl.render() == '<FOO>'255 256 262-def test_sum(env):257+def test_sum():258 tmpl = env.from_string(SUM)259 assert tmpl.render() == '21'260 261 267-def test_abs(env):262+def test_abs():263 tmpl = env.from_string(ABS)264 return tmpl.render() == '1|1'265 266 272-def test_round(env):267+def test_round():268 tmpl = env.from_string(ROUND)269 return tmpl.render() == '3.0|2.0|2.1|3.0'270 271 277-def test_xmlattr(env):272+def 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="<?>"' in out279 280 286-def test_sort1(env):281+def test_sort1():282 tmpl = env.from_string(SORT1)283 assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'284 285 291-def test_groupby(env):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 300-def test_filtertag(env):295+def test_filtertag():296 tmpl = env.from_string(FILTERTAG)297 assert tmpl.render() == 'fooBAR'298 299 10 unmodified lines310 tmpl = env.from_string('{{ string|replace("o", ">x<") }}')311 assert tmpl.render(string=Markup('foo')) == 'f>x<>x<'312 313 319-def test_forceescape(env):314+def test_forceescape():315 tmpl = env.from_string('{{ x|forceescape }}')316 assert tmpl.render(x=Markup('<div />')) == u'<div />'317 318 4 unmodified lines323 tmpl = env.from_string('{{ "<div>foo</div>" }}')324 assert tmpl.render() == '<div>foo</div>'325 326 332-def test_sort2(env):327+def test_sort2():328 assert env.from_string(SORT2).render() == "['Bar', 'blah', 'foo']"modified:tests/test_forloop.py+26 added-27 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9+from jinja2 import Environment10 from jinja2.exceptions import UndefinedError, TemplateSyntaxError11 11-import conftest12-if conftest.NOSE:13- from nose.tools import assert_raises as raises12+from nose.tools import assert_raises14-else:15- from py.test import raises13 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 %}\26 unmodified lines47 LOOPUNASSIGNABLE = '''\48 {% for loop in seq %}...{% endfor %}'''49 50 52-def test_simple(env):51+def test_simple():52 tmpl = env.from_string(SIMPLE)53 assert tmpl.render(seq=range(10)) == '0123456789'54 55 57-def test_else(env):56+def test_else():57 tmpl = env.from_string(ELSE)58 assert tmpl.render() == '...'59 60 62-def test_empty_blocks(env):61+def test_empty_blocks():62 tmpl = env.from_string(EMPTYBLOCKS)63 assert tmpl.render() == '<>'64 65 67-def test_context_vars(env):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('|')8 unmodified lines79 assert one_last == 'False' and two_last == 'True'80 assert one_length == two_length == '2'81 82 84-def test_cycling(env):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>' * 487 88 90-def test_scope(env):89+def test_scope():90 tmpl = env.from_string(SCOPE)91 output = tmpl.render(seq=range(10))92 assert not output93 94 96-def test_varlen(env):95+def 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'102 103 105-def test_noniter(env):104+def test_noniter():105 tmpl = env.from_string(NONITER)107- raises(TypeError, tmpl.render)106+ assert_raises(TypeError, tmpl.render)107 108 110-def test_recursive(env):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 119-def test_looploop(env):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 124-def test_reversed_bug(env):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 130-def test_loop_errors(env):129+def 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() == ''134 135 137-def test_loop_filter(env):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 144-def test_loop_unassignable(env):145- raises(TemplateSyntaxError, env.from_string, LOOPUNASSIGNABLE)143+def test_loop_unassignable():144+ assert_raises(TemplateSyntaxError, env.from_string, LOOPUNASSIGNABLE)145 146 148-def test_scoped_special_var(env):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 154-def test_scoped_loop_var(env):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 163-def test_recursive_empty_loop_iter(env):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 170-def test_call_in_loop(env):169+def test_call_in_loop():170 t = env.from_string('''171 {%- macro do_something() -%}172 [{{ caller() }}]173 {%- endmacro %}6 unmodified lines180 ''')181 assert t.render() == '[1][2][3]'182 183 185-def test_scoping_bug(env):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) -}}2 unmodified linesmodified:tests/test_heavy.py+4 added-4 removed
8 unmodified lines9 10 :copyright: Copyright 2009 by the Jinja Team.11 :license: BSD.12 """13+from jinja2 import Environment14+env = Environment()15 14-import conftest16 16-17-def test_assigned_scoping(env):17+def test_assigned_scoping():18 t = env.from_string('''19 {%- for item in (1, 2, 3, 4) -%}20 [{{ item }}]21 {%- endfor %}19 unmodified lines41 ''')42 assert t.render() == '[1][2][3][4]42'43 44 45-def test_closure_scoping(env):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 %}24 unmodified linesmodified:tests/test_i18n.py+3 added-7 removed
7 unmodified lines8 """9 from jinja2 import Environment, DictLoader, contextfunction10 from jinja2.exceptions import TemplateAssertionError11 12-import conftest13-if conftest.NOSE:14- from nose.tools import assert_raises as raises12+from nose.tools import assert_raises15-else:16- from py.test import raises13 14 templates = {15 'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'16 '{% block body %}{% endblock %}',55 unmodified lines72 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'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 %}')78 79 80 def test_trans_stringformatting():81 tmpl = i18n_env.get_template('stringformat.html')16 unmodified linesmodified:tests/test_ifcondition.py+8 added-7 removed
5 unmodified lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 10-import conftest10+from jinja2 import Environment11+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 19-def test_simple(env):20+def test_simple():21 tmpl = env.from_string(SIMPLE)22 assert tmpl.render() == '...'23 24 24-def test_elif(env):25+def test_elif():26 tmpl = env.from_string(ELIF)27 assert tmpl.render() == '...'28 29 29-def test_else(env):30+def test_else():31 tmpl = env.from_string(ELSE)32 assert tmpl.render() == '...'33 34 34-def test_empty(env):35+def test_empty():36 tmpl = env.from_string(EMPTY)37 assert tmpl.render() == '[]'38 39 39-def test_complete(env):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 45-def test_no_scope(env):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'modified:tests/test_imports.py+2 added-6 removed
7 unmodified lines8 """9 from jinja2 import Environment, DictLoader10 from jinja2.exceptions import TemplateNotFound11 12-import conftest13-if conftest.NOSE:14- from nose.tools import assert_raises as raises12+from nose.tools import assert_raises15-else:16- from py.test import raises13 14 15 test_env = Environment(loader=DictLoader(dict(16 module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',28 unmodified lines45 46 47 def 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 linesmodified:tests/test_inheritance.py+16 added-10 removed
8 unmodified lines9 10 from jinja2 import Environment, DictLoader11 from jinja2.exceptions import TemplateSyntaxError12 13-import conftest14-conftest.GlobalLoader.scope = globals()13 16-14 LAYOUTTEMPLATE = '''\15 |{% block block1 %}block 1 from layout{% endblock %}16 |{% block block2 %}block 2 from layout{% endblock %}17 |{% block block3 %}30 unmodified lines48 {% endif %}49 {% endblock %}50 '''51 52+env = Environment(loader=DictLoader({53+ 'layout': LAYOUTTEMPLATE,54+ 'level1': LEVEL1TEMPLATE,55+ 'level2': LEVEL2TEMPLATE,56+ 'level3': LEVEL3TEMPLATE,57+ 'level4': LEVEL4TEMPLATE,58+ 'working': WORKINGTEMPLATE59+}), trim_blocks=True)60+55-def test_layout(env):61+def 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|')65 66 61-def test_level1(env):67+def 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|')71 72 67-def test_level2(env):73+def 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|')77 78 73-def test_level3(env):79+def 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|')83 84 79-def test_level4(env):85+def 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 lines101 tmpl = env.get_template('c')102 assert tmpl.render() == '--INTRO--|BEFORE|[(INNER)]|AFTER'103 104 99-def test_working(env):105+def test_working():106 tmpl = env.get_template('working')107 108 103-def test_reuse_blocks(env):109+def test_reuse_blocks():110 tmpl = env.from_string('{{ self.foo() }}|{% block foo %}42{% endblock %}|{{ self.foo() }}')111 assert tmpl.render() == '42|42|42'112 113 84 unmodified linesmodified:tests/test_lexer.py+6 added-5 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9+from jinja2 import Environment10 10-import conftest11+env = Environment()12 13 14 RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{% endraw %}'15 BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''5 unmodified lines21 </ul>'''22 BYTEFALLBACK = u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}'''23 24 24-def test_raw(env):25+def test_raw():26 tmpl = env.from_string(RAW)27 assert tmpl.render() == 'foo|{{ bar }}|{% baz %}'28 29 11 unmodified lines41 assert tmpl.render(seq=range(3)) == ("<ul>\n <li>0</li>\n "42 "<li>1</li>\n <li>2</li>\n</ul>")43 44 44-def test_string_escapes(env):45+def 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'50 51 51-def test_bytefallback(env):52+def test_bytefallback():53 tmpl = env.from_string(BYTEFALLBACK)54 assert tmpl.render() == u"'foo'|u'b\\xe4r'"55 56 56-def test_operators(env):57+def test_operators():58 from jinja2.lexer import operators59 for test, expect in operators.iteritems():60 if test in '([{}])':61 continue12 unmodified linesmodified:tests/test_loaders.py+8 added-12 removed
11 unmodified lines12 from jinja2 import Environment, loaders13 from jinja2.loaders import split_template_path14 from jinja2.exceptions import TemplateNotFound15 16-import conftest17-if conftest.NOSE:18- from nose.tools import assert_raises as raises16+from nose.tools import assert_raises19-else:20- from py.test import raises17 18 19 dict_loader = loaders.DictLoader({20 'justdict.html': 'FOO'11 unmodified lines32 def 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')37 38 39 def 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')44 45 46 def 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')53 54 55 def 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')62 63 64 def 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')69 70 71 def 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')78 79 80 def test_caching():81 changed = False25 unmodified lines107 108 def 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 lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 10-import conftest11-conftest.GlobalLoader.scope = globals()10+from jinja2 import Environment, DictLoader11 12+env = Environment(trim_blocks=True)13 14+15 SIMPLE = '''\16 {% macro say_hello(name) %}Hello {{ name }}!{% endmacro %}17 {{ say_hello('Peter') }}\18 '''33 unmodified lines52 53 INCLUDETEMPLATE = '''{% macro test(foo) %}[{{ foo }}]{% endmacro %}'''54 55 55-def test_simple(env):56+def test_simple():57 tmpl = env.from_string(SIMPLE)58 assert tmpl.render() == 'Hello Peter!'59 60 60-def test_scoping(env):61+def test_scoping():62 tmpl = env.from_string(SCOPING)63 assert tmpl.render() == 'foo|bar'64 65 65-def test_arguments(env):66+def 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'69 70 70-def test_varargs(env):71+def test_varargs():72 tmpl = env.from_string(VARARGS)73 assert tmpl.render() == '1|2|3'74 75 75-def test_simple_call(env):76+def test_simple_call():77 tmpl = env.from_string(SIMPLECALL)78 assert tmpl.render() == '[[data]]'79 80 80-def test_complex_call(env):81+def test_complex_call():82 tmpl = env.from_string(COMPLEXCALL)83 assert tmpl.render() == '[[data]]'84 85 85-def test_caller_undefined(env):86+def test_caller_undefined():87 tmpl = env.from_string(CALLERUNDEFINED)88 assert tmpl.render() == 'True'89 90 90-def test_include(env):91+def 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]'95 96 95-def test_macro_api(env):97+def 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 linesmodified:tests/test_old_bugs.py+8 added-10 removed
8 unmodified lines9 :license: BSD.10 """11 from jinja2 import Environment, DictLoader, TemplateSyntaxError12 13-import conftest14-if conftest.NOSE:15- from nose.tools import assert_raises as raises16-else:17- from py.test import raises13+env = Environment()14 15+from nose.tools import assert_raises16 17+18 def 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 lines33 assert t.render(expr=False) == '[[title]](1)(2)(3)'34 assert t.render(expr=True) == '((title))'35 36 39-def test_urlize_filter_escaping(env):37+def 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/<foo">http://www.example.org/<foo</a>'40 41 44-def test_loop_call_loop(env):42+def test_loop_call_loop():43 tmpl = env.from_string('''44 45 {% macro test() %}46 {{ caller() }}13 unmodified lines60 61 62 def 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')66 67 70-def test_old_macro_loop_scoping_bug(env):68+def 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 lines7 :license: BSD, see LICENSE for more details.8 """9 from jinja2 import Environment10 11-import conftest11+env = Environment()12 13 14 PHP_SYNTAX = '''\15 <!-- I'm a comment, I'm not interesting -->\67 unmodified lines83 tmpl = env.from_string(COMMENT_SYNTAX)84 assert tmpl.render(seq=range(5)) == '01234'85 86 87-def test_balancing(env):87+def test_balancing():88 tmpl = env.from_string(BALANCING)89 assert tmpl.render() == 'bar'90 91 92-def test_start_comment(env):92+def test_start_comment():93 tmpl = env.from_string(STARTCOMMENT)94 assert tmpl.render().strip() == 'foo'95 96 20 unmodified linesmodified:tests/test_security.py+12 added-18 removed
11 unmodified lines12 from jinja2 import Markup, escape13 from jinja2.exceptions import SecurityError, TemplateSyntaxError14 15 16-import conftest17-if conftest.NOSE:18- from nose.tools import assert_raises as raises16+from nose.tools import assert_raises19- import sys20- MODULE = sys.modules[__name__]21-else:22- from py.test import raises17 18 class PrivateStuff(object):19 20 def bar(self):16 unmodified lines37 38 39 def 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())43 Traceback (most recent call last):44 ...45 SecurityError: <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())47 u'23'48 55->>> env.from_string("{{ foo._foo() }}").render(foo=MODULE.PublicStuff())49+>>> env.from_string("{{ foo._foo() }}").render(foo=PublicStuff())50 Traceback (most recent call last):51 ...52 SecurityError: 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())54 u'23'55 56 >>> env.from_string("{{ foo.__class__ }}").render(foo=42)57 u''7 unmodified lines65 66 67 def 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 %}")73 74 75 def test_immutable_environment():76 '''83->>> env = MODULE.ImmutableSandboxedEnvironment()77+>>> env = ImmutableSandboxedEnvironment()78 >>> env.from_string('{{ [].append(23) }}').render()79 Traceback (most recent call last):80 ...81 SecurityError: access to attribute 'append' of 'list' object is unsafe.55 unmodified lines137 138 def 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 lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 10-import conftest11-if conftest.NOSE:12- env = conftest.simple_env10+from jinja2 import Environment11+env = Environment()12 13 14 def test_basic_streaming():15 r"""42 unmodified linesmodified:tests/test_syntax.py+34 added-37 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from jinja2 import Environment, DictLoader9+from jinja2 import Environment10 from jinja2.exceptions import TemplateSyntaxError, UndefinedError11 12-import conftest13-if conftest.NOSE:14- from nose.tools import assert_raises as raises12+from nose.tools import assert_raises15-else:16- from py.test import raises13 14+env = Environment()15 16+17 CALL = '''{{ foo('a', c='d', e='f', *['b'], **{'g': 'h'}) }}'''18 SLICING = '''{{ [1, 2, 3][:] }}|{{ [1, 2, 3][::-1] }}'''19 ATTR = '''{{ foo.bar }}|{{ foo['bar'] }}'''20 SUBSCRIPT = '''{{ foo[0] }}|{{ foo[-1] }}'''23 unmodified lines44 TRAILINGCOMMA = '''{{ (1, 2,) }}|{{ [1, 2,] }}|{{ {1: 2,} }}'''45 46 47 def 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'52 53 57-def test_slicing(env):54+def test_slicing():55 tmpl = env.from_string(SLICING)56 assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'57 58 62-def test_attr(env):59+def test_attr():60 tmpl = env.from_string(ATTR)61 assert tmpl.render(foo={'bar': 42}) == '42|42'62 63 67-def test_subscript(env):64+def test_subscript():65 tmpl = env.from_string(SUBSCRIPT)66 assert tmpl.render(foo=[0, 1, 2]) == '0|2'67 68 72-def test_tuple(env):69+def test_tuple():70 tmpl = env.from_string(TUPLE)71 assert tmpl.render() == '()|(1,)|(1, 2)'72 73 77-def test_math(env):74+def test_math():75 tmpl = env.from_string(MATH)76 assert tmpl.render() == '1.5|8'77 78 82-def test_div(env):79+def test_div():80 tmpl = env.from_string(DIV)81 assert tmpl.render() == '1|1.5|1'82 83 87-def test_unary(env):84+def test_unary():85 tmpl = env.from_string(UNARY)86 assert tmpl.render() == '3|-3'87 88 92-def test_concat(env):89+def test_concat():90 tmpl = env.from_string(CONCAT)91 assert tmpl.render() == '[1, 2]foo'92 93 97-def test_compare(env):94+def test_compare():95 tmpl = env.from_string(COMPARE)96 assert tmpl.render() == 'True|True|True|True|True'97 98 102-def test_inop(env):99+def test_inop():100 tmpl = env.from_string(INOP)101 assert tmpl.render() == 'True|False'102 103 107-def test_literals(env):104+def test_literals():105 tmpl = env.from_string(LITERALS)106 assert tmpl.render().lower() == '[]|{}|()'107 108 112-def test_bool(env):109+def test_bool():110 tmpl = env.from_string(BOOL)111 assert tmpl.render() == 'False|True|True'112 113 117-def test_grouping(env):114+def test_grouping():115 tmpl = env.from_string(GROUPING)116 assert tmpl.render() == 'False'117 118 122-def test_django_attr(env):119+def test_django_attr():120 tmpl = env.from_string(DJANGOATTR)121 assert tmpl.render() == '1|1'122 123 127-def test_conditional_expression(env):124+def test_conditional_expression():125 tmpl = env.from_string(CONDEXPR)126 assert tmpl.render() == '0'127 128 132-def test_short_conditional_expression(env):129+def test_short_conditional_expression():130 tmpl = env.from_string('<{{ 1 if false }}>')131 assert tmpl.render() == '<>'132 133 tmpl = env.from_string('<{{ (1 if false).bar }}>')137- raises(UndefinedError, tmpl.render)134+ assert_raises(UndefinedError, tmpl.render)135 136 140-def test_filter_priority(env):137+def test_filter_priority():138 tmpl = env.from_string(FILTERPRIORITY)139 assert tmpl.render() == 'FOOBAR'140 141 145-def test_function_calls(env):142+def test_function_calls():143 tests = [144 (True, '*foo, bar'),145 (True, '*foo, *bar'),146 (True, '*foo, bar=42'),6 unmodified lines153 (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)160 161 165-def test_tuple_expr(env):162+def test_tuple_expr():163 for tmpl in TUPLETEMPLATES:164 print tmpl165 assert env.from_string(tmpl)166 167 171-def test_trailing_comma(env):168+def test_trailing_comma():169 tmpl = env.from_string(TRAILINGCOMMA)170 assert tmpl.render().lower() == '(1, 2)|[1, 2]|{1: 2}'171 172 176-def test_block_end_name(env):173+def 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 %}')176 177 181-def test_contant_casing(env):178+def 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)184 185 189-def test_test_chaining(env):190- raises(TemplateSyntaxError, env.from_string, '{{ foo is string is sequence }}')186+def 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'189 190 194-def test_string_concatenation(env):191+def test_string_concatenation():192 tmpl = env.from_string('{{ "foo" "bar" "baz" }}')193 assert tmpl.render() == 'foobarbaz'194 195 199-def test_notin(env):196+def 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)200 201 205-def test_implicit_subscribed_tuple(env):202+def 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 linemodified:tests/test_tests.py+11 added-12 removed
5 unmodified lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 from jinja2 import Environment, Markup10+env = Environment()11 11-import conftest12 13-13 DEFINED = '''{{ missing is defined }}|{{ true is defined }}'''14 EVEN = '''{{ 1 is even }}|{{ 2 is even }}'''15 LOWER = '''{{ "foo" is lower }}|{{ "FOO" is lower }}'''16 ODD = '''{{ 1 is odd }}|{{ 2 is odd }}'''17 unmodified lines34 {{ 42 is callable }}35 {{ range(5) is iterable }}'''36 37 39-def test_defined(env):38+def test_defined():39 tmpl = env.from_string(DEFINED)40 assert tmpl.render() == 'False|True'41 42 44-def test_even(env):43+def test_even():44 tmpl = env.from_string(EVEN)45 assert tmpl.render() == 'False|True'46 47 49-def test_odd(env):48+def test_odd():49 tmpl = env.from_string(ODD)50 assert tmpl.render() == 'True|False'51 52 54-def test_lower(env):53+def test_lower():54 tmpl = env.from_string(LOWER)55 assert tmpl.render() == 'True|False'56 57 59-def test_typechecks(env):58+def test_typechecks():59 tmpl = env.from_string(TYPECHECKS)60 assert tmpl.render() == ''61 62 64-def test_sequence(env):63+def test_sequence():64 tmpl = env.from_string(SEQUENCE)65 assert tmpl.render() == 'True|True|False'66 67 69-def test_upper(env):68+def test_upper():69 tmpl = env.from_string(UPPER)70 assert tmpl.render() == 'True|False'71 72 74-def test_sameas(env):73+def test_sameas():74 tmpl = env.from_string(SAMEAS)75 assert tmpl.render(foo=False) == 'True|False'76 77 79-def test_typechecks(env):78+def 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 )84 85 87-def test_no_paren_for_arg1(env):86+def test_no_paren_for_arg1():87 tmpl = env.from_string(NOPARENFORARG1)88 assert tmpl.render(foo=None) == 'True'89 90 4 unmodified linesmodified:tests/test_undefined.py+2 added-6 removed
7 unmodified lines8 """9 from jinja2 import Template10 from jinja2.exceptions import UndefinedError11 12-import conftest13-if conftest.NOSE:14- from nose.tools import assert_raises as raises12+from nose.tools import assert_raises15-else:16- from py.test import raises13 14 15 def test_default_undefined():16 '''65 unmodified lines82 83 84 def 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 lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 import gc10-from jinja2 import escape, is_undefined10+from jinja2 import escape, is_undefined, Environment11 from jinja2.utils import Cycler12 from jinja2.exceptions import TemplateSyntaxError13 14-import conftest15-if conftest.NOSE:16- from nose.tools import assert_raises as raises14+from nose.tools import assert_raises17-else:18- from py.test import raises15 16+env = Environment()17 18+19 UNPACKING = '''{% for a, b, c in [[1, 2, 3]] %}{{ a }}|{{ b }}|{{ c }}{% endfor %}'''20 RAW = '''{% raw %}{{ FOO }} and {% BAR %}{% endraw %}'''21 CONST = '''{{ true }}|{{ false }}|{{ none }}|\22 {{ none is defined }}|{{ missing is defined }}'''3 unmodified lines26 CONSTASS1 = '''{% set true = 42 %}'''27 CONSTASS2 = '''{% for none in seq %}{% endfor %}'''28 29 32-def test_unpacking(env):30+def test_unpacking():31 tmpl = env.from_string(UNPACKING)32 assert tmpl.render() == '1|2|3'33 34 37-def test_raw(env):35+def test_raw():36 tmpl = env.from_string(RAW)37 assert tmpl.render() == '{{ FOO }} and {% BAR %}'38 39 42-def test_const(env):40+def test_const():41 tmpl = env.from_string(CONST)42 assert tmpl.render() == 'True|False|None|True|False'43 44 47-def test_const_assign(env):45+def test_const_assign():46 for tmpl in CONSTASS1, CONSTASS2:49- raises(TemplateSyntaxError, env.from_string, tmpl)47+ assert_raises(TemplateSyntaxError, env.from_string, tmpl)48 49 52-def test_localset(env):50+def test_localset():51 tmpl = env.from_string(LOCALSET)52 assert tmpl.render() == '0'53 54 9 unmodified lines64 assert len(counts) == 1, 'ouch, c extension seems to leak objects'65 66 67 def test_item_and_attribute():70- from jinja2 import Environment68 from jinja2.sandbox import SandboxedEnvironment69 70 for env in Environment(), SandboxedEnvironment():71 tmpl = env.from_string('{{ foo.items() }}')4 unmodified lines76 assert tmpl.render(foo={'items': 42}) == '42'77 78 79 def test_finalizer():83- from jinja2 import Environment80 def finalize_none_empty(value):81 if value is None:82 value = u''83 return value15 unmodified lines99 c.reset()100 assert c.current == 1101 102 107-def test_expressions(env):103+def 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 linesdeleted:fabfile.py-40 removed
1-# -*- coding: utf-8 -*-2-"""3- Jinja fabfile4- ~~~~~~~~~~~~~5-6- Shortcuts for various tasks.7-8- :copyright: Copyright 2008 by Armin Ronacher.9- :license: BSD.10-"""11-12-13-def test():14- """Run the testsuite."""15- local("cd tests; py.test")16-17-18-def pylint():19- """Run pylint."""20- local("pylint --rcfile scripts/pylintrc jinja")21-22-23-def 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()38-39- local('hg tag -m "%s" "%s"' % ('tagged %r' % version, version))40- local('python setup.py release sdist upload')