Skip to content
Myr

merged.

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 · parents 3b336c8, c7e6c6d · Browse files · 21 files+141 added−31 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+141 added−31 removed

  • tests:+135 added−31 removed
  • other:+6 added−0 removed

21 files+141 added−31 removed

modified:tests/conftest.py+14 added
17 unmodified lines
18from 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 all
28 unmodified lines
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:
88 unmodified lines
modified:tests/test_debug.py+13 added-5 removed
9 unmodified lines
10"""11from jinja2 import Environment12from test_loaders import filesystem_loader1314import conftest15if conftest.NOSE:16 import sys17 MODULE = sys.modules[__name__]181920env = Environment(loader=filesystem_loader)212218test_runtime_error = '''23def test_runtime_error():24 '''25>>> tmpl = MODULE.env.get_template('broken.html')26>>> tmpl.render(fail=lambda: 1 / 0)27Traceback (most recent call last):28 File "loaderres/templates/broken.html", line 2, in top-level template code
3 unmodified lines
32ZeroDivisionError: integer division or modulo by zero33'''343530test_syntax_error = '''36def test_syntax_error():37 '''38>>> tmpl = MODULE.env.get_template('syntaxerror.html')39Traceback (most recent call last):40 ...34 File "loaderres/templates/syntaxerror.html", line 435 {% endif %}41TemplateSyntaxError: unknown tag 'endif'42 File "loaderres/templates\\syntaxerror.html", line 443 {% endif %}44'''454640test_regular_syntax_error = '''47def test_regular_syntax_error():48 '''49>>> from jinja2.exceptions import TemplateSyntaxError50>>> raise TemplateSyntaxError('wtf', 42)51Traceback (most recent call last):52 ...
5 unmodified lines
modified:tests/test_filters.py+10 added-8 removed
6 unmodified lines
7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Markup, Environment1011import conftest121314CAPITALIZE = '''{{ "foo bar"|capitalize }}'''15CENTER = '''{{ "foo"|center(9) }}'''16DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\17{{ false|default('no', true) }}|{{ given|default("no") }}'''
42 unmodified lines
60ROUND = '''{{ 2.7|round }}|{{ 2.1|round }}|\61{{ 2.1234|round(2, 'floor') }}|{{ 2.1|round(0, 'ceil') }}'''62XMLATTR = '''{{ {'foo': 42, 'bar': 23, 'fish': none,63'spam': missing, 'blub:blub': '<?>'}|xmlattr }}'''62SORT = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''64SORT1 = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''65GROUPBY = '''{% for grouper, list in [{'foo': 1, 'bar': 2},66 {'foo': 2, 'bar': 3},67 {'foo': 1, 'bar': 1},68 {'foo': 3, 'bar': 4}]|groupby('foo') -%}69{{ grouper }}: {{ list|join(', ') }}70{% endfor %}'''71FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''70SORT = '''{{ ['foo', 'Bar', 'blah']|sort }}'''72SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''737475def test_capitalize(env):76 tmpl = env.from_string(CAPITALIZE)
143 unmodified lines
220 tmpl = env.from_string(TITLE)221 assert tmpl.render() == "Foo Bar"222223222def test_truncate(env):224def NOT_WORKING_test_truncate(env):225 tmpl = env.from_string(TRUNCATE)226 assert tmpl.render() == 'foo'227228227def test_truncate(env):229def test_truncate2(env):230 tmpl = env.from_string(TRUNCATE)231 out = tmpl.render(data='foobar baz bar' * 1000,232 smalldata='foobar baz bar')233 assert out == 'foobar baz barf>>>|foobar baz >>>|foobar baz bar'
48 unmodified lines
282 assert 'bar="23"' in out283 assert 'blub:blub="&lt;?&gt;"' in out284285284def test_sort(env):285 tmpl = env.from_string(SORT)286def test_sort1(env):287 tmpl = env.from_string(SORT1)288 assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'289290291def test_groupby(env):
36 unmodified lines
328 tmpl = env.from_string('{{ "<div>foo</div>" }}')329 assert tmpl.render() == '&lt;div&gt;foo&lt;/div&gt;'330331330def test_sort(env):331 assert env.from_string(SORT).render() == "['Bar', 'blah', 'foo']"332def test_sort2(env):333 assert env.from_string(SORT2).render() == "['Bar', 'blah', 'foo']"
modified:tests/test_forloop.py+6 added-1 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises9from jinja2.exceptions import UndefinedError, TemplateSyntaxError1011import conftest12if conftest.NOSE:13 from nose.tools import assert_raises as raises14else:15 from py.test import raises161718SIMPLE = '''{% for item in seq %}{{ item }}{% endfor %}'''19ELSE = '''{% for item in seq %}XXX{% else %}...{% endfor %}'''20EMPTYBLOCKS = '''<{% for item in seq %}{% else %}{% endfor %}>'''21CONTEXTVARS = '''{% for item in seq %}\
170 unmodified lines
modified:tests/test_heavy.py+2 added
9 unmodified lines
10 :copyright: Copyright 2009 by the Jinja Team.11 :license: BSD.12"""1314import conftest151617def test_assigned_scoping(env):18 t = env.from_string('''19 {%- for item in (1, 2, 3, 4) -%}20 [{{ item }}]
53 unmodified lines
modified:tests/test_i18n.py+6 added-1 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises9from jinja2 import Environment, DictLoader, contextfunction10from jinja2.exceptions import TemplateAssertionError1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises15else:16 from py.test import raises1718templates = {19 'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'20 '{% block body %}{% endblock %}',21 'child.html': '{% extends "master.html" %}{% block body %}'
80 unmodified lines
modified:tests/test_ifcondition.py+3 added
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910import conftest111213SIMPLE = '''{% if true %}...{% endif %}'''14ELIF = '''{% if false %}XXX{% elif true %}...{% else %}XXX{% endif %}'''15ELSE = '''{% if false %}XXX{% else %}...{% endif %}'''16EMPTY = '''[{% if true %}{% else %}{% endif %}]'''
33 unmodified lines
modified:tests/test_imports.py+6 added-1 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises9from jinja2 import Environment, DictLoader10from jinja2.exceptions import TemplateNotFound1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises15else:16 from py.test import raises171819test_env = Environment(loader=DictLoader(dict(20 module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',21 header='[{{ foo }}|{{ 23 }}]',22 o_printer='({{ o }})'
79 unmodified lines
modified:tests/test_inheritance.py+5 added
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910from jinja2 import Environment, DictLoader11from jinja2.exceptions import TemplateSyntaxError1213import conftest14conftest.GlobalLoader.scope = globals()151617LAYOUTTEMPLATE = '''\18|{% block block1 %}block 1 from layout{% endblock %}19|{% block block2 %}block 2 from layout{% endblock %}20|{% block block3 %}
171 unmodified lines
modified:tests/test_lexer.py+3 added
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910import conftest111213RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{% endraw %}'14BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''15COMMENTS = '''\16<ul>
56 unmodified lines
modified:tests/test_loaders.py+6 added-1 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""910from py.test import raises10import time11import tempfile12from 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 raises19else:20 from py.test import raises212223dict_loader = loaders.DictLoader({24 'justdict.html': 'FOO'25})26package_loader = loaders.PackageLoader('loaderres', 'templates')
89 unmodified lines
modified:tests/test_macros.py+4 added
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()121314SIMPLE = '''\15{% macro say_hello(name) %}Hello {{ name }}!{% endmacro %}16{{ say_hello('Peter') }}\17'''
93 unmodified lines
modified:tests/test_old_bugs.py+6 added-1 removed
6 unmodified lines
78 :copyright: (c) 2009 by the Jinja Team.9 :license: BSD.10"""11from py.test import raises11from jinja2 import Environment, DictLoader, TemplateSyntaxError1213import conftest14if conftest.NOSE:15 from nose.tools import assert_raises as raises16else:17 from py.test import raises181920def test_keyword_folding():21 env = Environment()22 env.filters['testing'] = lambda value, some: value + some23 assert env.from_string("{{ 'test'|testing(some='stuff') }}") \
50 unmodified lines
modified:tests/test_parser.py+3 added-1 removed
6 unmodified lines
7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment1011import conftest121314PHP_SYNTAX = '''\15<!-- I'm a comment, I'm not interesting -->\16<? for item in seq -?>17 <?= item ?>
79 unmodified lines
97def test_line_syntax():98 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')99 tmpl = env.from_string(MAKO_SYNTAX)100 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \99 range(5)101 range(5)102103 env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')104 tmpl = env.from_string(MAKO_SYNTAX_LINECOMMENTS)105 assert [int(x.strip()) for x in tmpl.render(seq=range(5)).split()] == \
11 unmodified lines
modified:tests/test_security.py+12 added-3 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises9from jinja2 import Environment10from jinja2.sandbox import SandboxedEnvironment, \11 ImmutableSandboxedEnvironment, unsafe12from jinja2 import Markup, escape13from jinja2.exceptions import SecurityError, TemplateSyntaxError141516import conftest17if conftest.NOSE:18 from nose.tools import assert_raises as raises19 import sys20 MODULE = sys.modules[__name__]21else:22 from py.test import raises2324class PrivateStuff(object):2526 def bar(self):27 return 23
13 unmodified lines
41 def __repr__(self):42 return 'PublicStuff'434438test_unsafe = '''45def test_unsafe():46 '''47>>> env = MODULE.SandboxedEnvironment()48>>> env.from_string("{{ foo.foo() }}").render(foo=MODULE.PrivateStuff())49Traceback (most recent call last):50 ...
26 unmodified lines
77 raises(TemplateSyntaxError, env.from_string,78 "{% for foo, bar.baz in seq %}...{% endfor %}")798073test_immutable_environment = '''81def test_immutable_environment():82 '''83>>> env = MODULE.ImmutableSandboxedEnvironment()84>>> env.from_string('{{ [].append(23) }}').render()85Traceback (most recent call last):86 ...
61 unmodified lines
modified:tests/test_streaming.py+10 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_env1311test_basic_streaming = r"""1415def test_basic_streaming():16 r"""17>>> tmpl = env.from_string("<ul>{% for item in seq %}<li>{{ loop.index "18... "}} - {{ item }}</li>{%- endfor %}</ul>")19>>> stream = tmpl.stream(seq=range(4))20>>> stream.next()
9 unmodified lines
30>>> stream.next()31u'</ul>'32"""3329test_buffered_streaming = r"""34def test_buffered_streaming():35 r"""36>>> tmpl = env.from_string("<ul>{% for item in seq %}<li>{{ loop.index "37... "}} - {{ item }}</li>{%- endfor %}</ul>")38>>> stream = tmpl.stream(seq=range(4))39>>> stream.enable_buffering(size=3)
2 unmodified lines
42>>> stream.next()43u'<li>3 - 2</li><li>4 - 3</li></ul>'44"""4540test_streaming_behavior = r"""46def test_streaming_behavior():47 r"""48>>> tmpl = env.from_string("")49>>> stream = tmpl.stream()50>>> stream.buffered51False
7 unmodified lines
modified:tests/test_syntax.py+6 added-1 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises9from jinja2 import Environment, DictLoader10from jinja2.exceptions import TemplateSyntaxError, UndefinedError1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises15else:16 from py.test import raises171819CALL = '''{{ foo('a', c='d', e='f', *['b'], **{'g': 'h'}) }}'''20SLICING = '''{{ [1, 2, 3][:] }}|{{ [1, 2, 3][::-1] }}'''21ATTR = '''{{ foo.bar }}|{{ foo['bar'] }}'''22SUBSCRIPT = '''{{ foo[0] }}|{{ foo[-1] }}'''
188 unmodified lines
modified:tests/test_tests.py+2 added
6 unmodified lines
7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment, Markup1011import conftest121314DEFINED = '''{{ missing is defined }}|{{ true is defined }}'''15EVEN = '''{{ 1 is even }}|{{ 2 is even }}'''16LOWER = '''{{ "foo" is lower }}|{{ "FOO" is lower }}'''17ODD = '''{{ 1 is odd }}|{{ 2 is odd }}'''
78 unmodified lines
modified:tests/test_undefined.py+12 added-4 removed
4 unmodified lines
56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises9from jinja2 import Template10from jinja2.exceptions import UndefinedError1112import conftest13if conftest.NOSE:14 from nose.tools import assert_raises as raises15else:16 from py.test import raises1714test_default_undefined = '''1819def test_default_undefined():20 '''21>>> from jinja2 import Environment, Undefined22>>> env = Environment(undefined=Undefined)23>>> env.from_string('{{ missing }}').render()24u''
10 unmodified lines
35>>> env.from_string('{{ not missing }}').render()36u'True'37'''3833test_debug_undefined = '''39def test_debug_undefined():40 '''41>>> from jinja2 import Environment, DebugUndefined42>>> env = Environment(undefined=DebugUndefined)43>>> env.from_string('{{ missing }}').render()44u'{{ missing }}'
10 unmodified lines
55>>> env.from_string('{{ not missing }}').render()56u'True'57'''5852test_strict_undefined = '''59def test_strict_undefined():60 '''61>>> from jinja2 import Environment, StrictUndefined62>>> env = Environment(undefined=StrictUndefined)63>>> env.from_string('{{ missing }}').render()64Traceback (most recent call last):
26 unmodified lines
modified:tests/test_various.py+6 added-1 removed
5 unmodified lines
6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9import gc10from py.test import raises10from jinja2 import escape, is_undefined11from jinja2.utils import Cycler12from jinja2.exceptions import TemplateSyntaxError1314import conftest15if conftest.NOSE:16 from nose.tools import assert_raises as raises17else:18 from py.test import raises192021UNPACKING = '''{% for a, b, c in [[1, 2, 3]] %}{{ a }}|{{ b }}|{{ c }}{% endfor %}'''22RAW = '''{% raw %}{{ FOO }} and {% BAR %}{% endraw %}'''23CONST = '''{{ true }}|{{ false }}|{{ none }}|\24{{ none is defined }}|{{ missing is defined }}'''
91 unmodified lines
modified:setup.cfg+6 added
2 unmodified lines
3tag_date = true45[aliases]6release = egg_info -RDb ''78[nosetests]9#verbosity=210detailed-errors=111cover-package=nose12where=tests