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
Provenance
- Commit
1b43b58- Tree
64b166f- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
3b336c8- Parent 2
c7e6c6d
21 files changed+141 added−31 removed
modified:tests/conftest.py+14 added
17 unmodified lines18 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 all28 unmodified lines67 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:88 unmodified linesmodified:tests/test_debug.py+13 added-5 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+20 env = Environment(loader=filesystem_loader)21 22 18-test_runtime_error = '''23+def test_runtime_error():24+ '''25 >>> tmpl = MODULE.env.get_template('broken.html')26 >>> tmpl.render(fail=lambda: 1 / 0)27 Traceback (most recent call last):28 File "loaderres/templates/broken.html", line 2, in top-level template code3 unmodified lines32 ZeroDivisionError: integer division or modulo by zero33 '''34 35 30-test_syntax_error = '''36+def test_syntax_error():37+ '''38 >>> tmpl = MODULE.env.get_template('syntaxerror.html')39 Traceback (most recent call last):40 ...34- File "loaderres/templates/syntaxerror.html", line 435- {% endif %}41 TemplateSyntaxError: unknown tag 'endif'42+ File "loaderres/templates\\syntaxerror.html", line 443+ {% endif %}44 '''45 46 40-test_regular_syntax_error = '''47+def test_regular_syntax_error():48+ '''49 >>> from jinja2.exceptions import TemplateSyntaxError50 >>> raise TemplateSyntaxError('wtf', 42)51 Traceback (most recent call last):52 ...5 unmodified linesmodified:tests/test_filters.py+10 added-8 removed
6 unmodified lines7 :license: BSD, see LICENSE for more details.8 """9 from jinja2 import Markup, Environment10 11+import conftest12 13+14 CAPITALIZE = '''{{ "foo bar"|capitalize }}'''15 CENTER = '''{{ "foo"|center(9) }}'''16 DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\17 {{ false|default('no', true) }}|{{ given|default("no") }}'''42 unmodified lines60 ROUND = '''{{ 2.7|round }}|{{ 2.1|round }}|\61 {{ 2.1234|round(2, 'floor') }}|{{ 2.1|round(0, 'ceil') }}'''62 XMLATTR = '''{{ {'foo': 42, 'bar': 23, 'fish': none,63 'spam': missing, 'blub:blub': '<?>'}|xmlattr }}'''62-SORT = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''64+SORT1 = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''65 GROUPBY = '''{% for grouper, list in [{'foo': 1, 'bar': 2},66 {'foo': 2, 'bar': 3},67 {'foo': 1, 'bar': 1},68 {'foo': 3, 'bar': 4}]|groupby('foo') -%}69 {{ grouper }}: {{ list|join(', ') }}70 {% endfor %}'''71 FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''70-SORT = '''{{ ['foo', 'Bar', 'blah']|sort }}'''72+SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''73 74 75 def test_capitalize(env):76 tmpl = env.from_string(CAPITALIZE)143 unmodified lines220 tmpl = env.from_string(TITLE)221 assert tmpl.render() == "Foo Bar"222 223 222-def test_truncate(env):224+def NOT_WORKING_test_truncate(env):225 tmpl = env.from_string(TRUNCATE)226 assert tmpl.render() == 'foo'227 228 227-def test_truncate(env):229+def 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 lines282 assert 'bar="23"' in out283 assert 'blub:blub="<?>"' in out284 285 284-def test_sort(env):285- tmpl = env.from_string(SORT)286+def test_sort1(env):287+ tmpl = env.from_string(SORT1)288 assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'289 290 291 def test_groupby(env):36 unmodified lines328 tmpl = env.from_string('{{ "<div>foo</div>" }}')329 assert tmpl.render() == '<div>foo</div>'330 331 330-def test_sort(env):331- assert env.from_string(SORT).render() == "['Bar', 'blah', 'foo']"332+def test_sort2(env):333+ assert env.from_string(SORT2).render() == "['Bar', 'blah', 'foo']"modified:tests/test_forloop.py+6 added-1 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from py.test import raises9 from jinja2.exceptions import UndefinedError, TemplateSyntaxError10 11+import conftest12+if conftest.NOSE:13+ from nose.tools import assert_raises as raises14+else:15+ from py.test import raises16 17+18 SIMPLE = '''{% for item in seq %}{{ item }}{% endfor %}'''19 ELSE = '''{% for item in seq %}XXX{% else %}...{% endfor %}'''20 EMPTYBLOCKS = '''<{% for item in seq %}{% else %}{% endfor %}>'''21 CONTEXTVARS = '''{% for item in seq %}\170 unmodified linesmodified:tests/test_heavy.py+2 added
9 unmodified lines10 :copyright: Copyright 2009 by the Jinja Team.11 :license: BSD.12 """13 14+import conftest15 16+17 def test_assigned_scoping(env):18 t = env.from_string('''19 {%- for item in (1, 2, 3, 4) -%}20 [{{ item }}]53 unmodified linesmodified:tests/test_i18n.py+6 added-1 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from py.test import raises9 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 raises15+else:16+ from py.test import raises17+18 templates = {19 'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'20 '{% block body %}{% endblock %}',21 'child.html': '{% extends "master.html" %}{% block body %}'80 unmodified linesmodified:tests/test_ifcondition.py+3 added
5 unmodified lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 10+import conftest11+12+13 SIMPLE = '''{% if true %}...{% endif %}'''14 ELIF = '''{% if false %}XXX{% elif true %}...{% else %}XXX{% endif %}'''15 ELSE = '''{% if false %}XXX{% else %}...{% endif %}'''16 EMPTY = '''[{% if true %}{% else %}{% endif %}]'''33 unmodified linesmodified:tests/test_imports.py+6 added-1 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from py.test import raises9 from jinja2 import Environment, DictLoader10 from jinja2.exceptions import TemplateNotFound11 12+import conftest13+if conftest.NOSE:14+ from nose.tools import assert_raises as raises15+else:16+ from py.test import raises17 18+19 test_env = Environment(loader=DictLoader(dict(20 module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',21 header='[{{ foo }}|{{ 23 }}]',22 o_printer='({{ o }})'79 unmodified linesmodified:tests/test_inheritance.py+5 added
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9+10 from jinja2 import Environment, DictLoader11 from jinja2.exceptions import TemplateSyntaxError12 13+import conftest14+conftest.GlobalLoader.scope = globals()15+16+17 LAYOUTTEMPLATE = '''\18 |{% block block1 %}block 1 from layout{% endblock %}19 |{% block block2 %}block 2 from layout{% endblock %}20 |{% block block3 %}171 unmodified linesmodified:tests/test_lexer.py+3 added
5 unmodified lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 10+import conftest11+12+13 RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{% endraw %}'14 BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''15 COMMENTS = '''\16 <ul>56 unmodified linesmodified:tests/test_loaders.py+6 added-1 removed
5 unmodified lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 10-from py.test import raises10 import time11 import tempfile12 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 raises19+else:20+ from py.test import raises21 22+23 dict_loader = loaders.DictLoader({24 'justdict.html': 'FOO'25 })26 package_loader = loaders.PackageLoader('loaderres', 'templates')89 unmodified linesmodified:tests/test_macros.py+4 added
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()12+13+14 SIMPLE = '''\15 {% macro say_hello(name) %}Hello {{ name }}!{% endmacro %}16 {{ say_hello('Peter') }}\17 '''93 unmodified linesmodified:tests/test_old_bugs.py+6 added-1 removed
6 unmodified lines7 8 :copyright: (c) 2009 by the Jinja Team.9 :license: BSD.10 """11-from py.test import raises11 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 raises18 19+20 def 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 linesmodified:tests/test_parser.py+3 added-1 removed
6 unmodified lines7 :license: BSD, see LICENSE for more details.8 """9 from jinja2 import Environment10 11+import conftest12 13+14 PHP_SYNTAX = '''\15 <!-- I'm a comment, I'm not interesting -->\16 <? for item in seq -?>17 <?= item ?>79 unmodified lines97 def 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)102 103 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 linesmodified:tests/test_security.py+12 added-3 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from py.test import raises9 from jinja2 import Environment10 from jinja2.sandbox import SandboxedEnvironment, \11 ImmutableSandboxedEnvironment, unsafe12 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 raises19+ import sys20+ MODULE = sys.modules[__name__]21+else:22+ from py.test import raises23+24 class PrivateStuff(object):25 26 def bar(self):27 return 2313 unmodified lines41 def __repr__(self):42 return 'PublicStuff'43 44 38-test_unsafe = '''45+def test_unsafe():46+ '''47 >>> env = MODULE.SandboxedEnvironment()48 >>> env.from_string("{{ foo.foo() }}").render(foo=MODULE.PrivateStuff())49 Traceback (most recent call last):50 ...26 unmodified lines77 raises(TemplateSyntaxError, env.from_string,78 "{% for foo, bar.baz in seq %}...{% endfor %}")79 80 73-test_immutable_environment = '''81+def test_immutable_environment():82+ '''83 >>> env = MODULE.ImmutableSandboxedEnvironment()84 >>> env.from_string('{{ [].append(23) }}').render()85 Traceback (most recent call last):86 ...61 unmodified linesmodified:tests/test_streaming.py+10 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_env13 11-test_basic_streaming = r"""14+15+def 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 lines30 >>> stream.next()31 u'</ul>'32 """33 29-test_buffered_streaming = r"""34+def 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 lines42 >>> stream.next()43 u'<li>3 - 2</li><li>4 - 3</li></ul>'44 """45 40-test_streaming_behavior = r"""46+def test_streaming_behavior():47+ r"""48 >>> tmpl = env.from_string("")49 >>> stream = tmpl.stream()50 >>> stream.buffered51 False7 unmodified linesmodified:tests/test_syntax.py+6 added-1 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from py.test import raises9 from jinja2 import Environment, DictLoader10 from jinja2.exceptions import TemplateSyntaxError, UndefinedError11 12+import conftest13+if conftest.NOSE:14+ from nose.tools import assert_raises as raises15+else:16+ from py.test import raises17 18+19 CALL = '''{{ foo('a', c='d', e='f', *['b'], **{'g': 'h'}) }}'''20 SLICING = '''{{ [1, 2, 3][:] }}|{{ [1, 2, 3][::-1] }}'''21 ATTR = '''{{ foo.bar }}|{{ foo['bar'] }}'''22 SUBSCRIPT = '''{{ foo[0] }}|{{ foo[-1] }}'''188 unmodified linesmodified:tests/test_tests.py+2 added
6 unmodified lines7 :license: BSD, see LICENSE for more details.8 """9 from jinja2 import Environment, Markup10 11+import conftest12 13+14 DEFINED = '''{{ missing is defined }}|{{ true is defined }}'''15 EVEN = '''{{ 1 is even }}|{{ 2 is even }}'''16 LOWER = '''{{ "foo" is lower }}|{{ "FOO" is lower }}'''17 ODD = '''{{ 1 is odd }}|{{ 2 is odd }}'''78 unmodified linesmodified:tests/test_undefined.py+12 added-4 removed
4 unmodified lines5 6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9-from py.test import raises9 from jinja2 import Template10 from jinja2.exceptions import UndefinedError11 12+import conftest13+if conftest.NOSE:14+ from nose.tools import assert_raises as raises15+else:16+ from py.test import raises17 14-test_default_undefined = '''18+19+def test_default_undefined():20+ '''21 >>> from jinja2 import Environment, Undefined22 >>> env = Environment(undefined=Undefined)23 >>> env.from_string('{{ missing }}').render()24 u''10 unmodified lines35 >>> env.from_string('{{ not missing }}').render()36 u'True'37 '''38 33-test_debug_undefined = '''39+def test_debug_undefined():40+ '''41 >>> from jinja2 import Environment, DebugUndefined42 >>> env = Environment(undefined=DebugUndefined)43 >>> env.from_string('{{ missing }}').render()44 u'{{ missing }}'10 unmodified lines55 >>> env.from_string('{{ not missing }}').render()56 u'True'57 '''58 52-test_strict_undefined = '''59+def test_strict_undefined():60+ '''61 >>> from jinja2 import Environment, StrictUndefined62 >>> env = Environment(undefined=StrictUndefined)63 >>> env.from_string('{{ missing }}').render()64 Traceback (most recent call last):26 unmodified linesmodified:tests/test_various.py+6 added-1 removed
5 unmodified lines6 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8 """9 import gc10-from py.test import raises10 from jinja2 import escape, is_undefined11 from jinja2.utils import Cycler12 from jinja2.exceptions import TemplateSyntaxError13 14+import conftest15+if conftest.NOSE:16+ from nose.tools import assert_raises as raises17+else:18+ from py.test import raises19 20+21 UNPACKING = '''{% for a, b, c in [[1, 2, 3]] %}{{ a }}|{{ b }}|{{ c }}{% endfor %}'''22 RAW = '''{% raw %}{{ FOO }} and {% BAR %}{% endraw %}'''23 CONST = '''{{ true }}|{{ false }}|{{ none }}|\24 {{ none is defined }}|{{ missing is defined }}'''91 unmodified linesmodified:setup.cfg+6 added
2 unmodified lines3 tag_date = true4 5 [aliases]6 release = egg_info -RDb ''7+8+[nosetests]9+#verbosity=210+detailed-errors=111+cover-package=nose12+where=tests