Skip to content
Myr

Added tests for the test functions (the jinja ones ^^)

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 4254936 · Browse files · 3 files+89 added−62 removed
This commit

State

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

Diff stats

3 files+89 added−62 removed

  • other:+89 added−62 removed

3 files+89 added−62 removed

modified:jinja2/testsuite/__init__.py+2 added-1 removed
42 unmodified lines
43 return self.assertRaises(*args, **kwargs)444546def suite():47 from jinja2.testsuite import ext, filters, core_tags, loader47 from jinja2.testsuite import ext, filters, tests, core_tags, loader48 suite = unittest.TestSuite()49 suite.addTest(ext.suite())50 suite.addTest(filters.suite())51 suite.addTest(tests.suite())52 suite.addTest(core_tags.suite())53 suite.addTest(loader.suite())54 return suite
modified:jinja2/testsuite/filters.py-61 removed
14 unmodified lines
1516env = Environment()171819CAPITALIZE = '''{{ "foo bar"|capitalize }}'''20CENTER = '''{{ "foo"|center(9) }}'''21DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\22{{ false|default('no', true) }}|{{ given|default("no") }}'''23DICTSORT = '''{{ foo|dictsort }}|\24{{ foo|dictsort(true) }}|\25{{ foo|dictsort(false, 'value') }}'''26BATCH = '''{{ foo|batch(3)|list }}|{{ foo|batch(3, 'X')|list }}'''27SLICE = '''{{ foo|slice(3)|list }}|{{ foo|slice(3, 'X')|list }}'''28ESCAPE = '''{{ '<">&'|escape }}'''29STRIPTAGS = '''{{ foo|striptags }}'''30FILESIZEFORMAT = '{{ 100|filesizeformat }}|\31{{ 1000|filesizeformat }}|\32{{ 1000000|filesizeformat }}|\33{{ 1000000000|filesizeformat }}|\34{{ 1000000000000|filesizeformat }}|\35{{ 100|filesizeformat(true) }}|\36{{ 1000|filesizeformat(true) }}|\37{{ 1000000|filesizeformat(true) }}|\38{{ 1000000000|filesizeformat(true) }}|\39{{ 1000000000000|filesizeformat(true) }}'40FIRST = '''{{ foo|first }}'''41FLOAT = '''{{ "42"|float }}|{{ "ajsghasjgd"|float }}|{{ "32.32"|float }}'''42FORMAT = '''{{ "%s|%s"|format("a", "b") }}'''43INDENT = '''{{ foo|indent(2) }}|{{ foo|indent(2, true) }}'''44INT = '''{{ "42"|int }}|{{ "ajsghasjgd"|int }}|{{ "32.32"|int }}'''45JOIN = '''{{ [1, 2, 3]|join("|") }}'''46LAST = '''{{ foo|last }}'''47LENGTH = '''{{ "hello world"|length }}'''48LOWER = '''{{ "FOO"|lower }}'''49PPRINT = '''{{ data|pprint }}'''50RANDOM = '''{{ seq|random }}'''51REVERSE = '''{{ "foobar"|reverse|join }}|{{ [1, 2, 3]|reverse|list }}'''52STRING = '''{{ range(10)|string }}'''53TITLE = '''{{ "foo bar"|title }}'''54TRIM = '''{{ " foo "|trim }}'''55TRUNCATE = '''{{ data|truncate(15, true, ">>>") }}|\56{{ data|truncate(15, false, ">>>") }}|\57{{ smalldata|truncate(15) }}'''58UPPER = '''{{ "foo"|upper }}'''59URLIZE = '''{{ "foo http://www.example.com/ bar"|urlize }}'''60WORDCOUNT = '''{{ "foo bar baz"|wordcount }}'''61BLOCK = '''{% filter lower|escape %}<HEHE>{% endfilter %}'''62CHAINING = '''{{ ['<foo>', '<bar>']|first|upper|escape }}'''63SUM = '''{{ [1, 2, 3, 4, 5, 6]|sum }}'''64ABS = '''{{ -1|abs }}|{{ 1|abs }}'''65ROUND = '''{{ 2.7|round }}|{{ 2.1|round }}|\66{{ 2.1234|round(2, 'floor') }}|{{ 2.1|round(0, 'ceil') }}'''67XMLATTR = '''{{ {'foo': 42, 'bar': 23, 'fish': none,68'spam': missing, 'blub:blub': '<?>'}|xmlattr }}'''69SORT1 = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''70GROUPBY = '''{% for grouper, list in [{'foo': 1, 'bar': 2},71 {'foo': 2, 'bar': 3},72 {'foo': 1, 'bar': 1},73 {'foo': 3, 'bar': 4}]|groupby('foo') -%}74{{ grouper }}: {{ list|join(', ') }}75{% endfor %}'''76FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''77SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''787919class FilterTestCase(JinjaTestCase):2021 def test_capitalize(self):22 tmpl = env.from_string('{{ "foo bar"|capitalize }}')
258 unmodified lines
added:jinja2/testsuite/tests.py+87 added
1# -*- coding: utf-8 -*-2"""3 jinja2.testsuite.tests4 ~~~~~~~~~~~~~~~~~~~~~~56 Who tests the tests?78 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import unittest12from jinja2.testsuite import JinjaTestCase1314from jinja2 import Markup, Environment1516env = Environment()171819class TestsTestCase(JinjaTestCase):2021 def test_defined(self):22 tmpl = env.from_string('{{ missing is defined }}|{{ true is defined }}')23 assert tmpl.render() == 'False|True'2425 def test_even(self):26 tmpl = env.from_string('''{{ 1 is even }}|{{ 2 is even }}''')27 assert tmpl.render() == 'False|True'2829 def test_odd(self):30 tmpl = env.from_string('''{{ 1 is odd }}|{{ 2 is odd }}''')31 assert tmpl.render() == 'True|False'3233 def test_lower(self):34 tmpl = env.from_string('''{{ "foo" is lower }}|{{ "FOO" is lower }}''')35 assert tmpl.render() == 'True|False'3637 def test_typechecks(self):38 tmpl = env.from_string('''39 {{ 42 is undefined }}40 {{ 42 is defined }}41 {{ 42 is none }}42 {{ none is none }}43 {{ 42 is number }}44 {{ 42 is string }}45 {{ "foo" is string }}46 {{ "foo" is sequence }}47 {{ [1] is sequence }}48 {{ range is callable }}49 {{ 42 is callable }}50 {{ range(5) is iterable }}51 ''')52 assert tmpl.render().split() == [53 'False', 'True', 'False', 'True', 'True', 'False',54 'True', 'True', 'True', 'True', 'False', 'True'55 ]5657 def test_sequence(self):58 tmpl = env.from_string(59 '{{ [1, 2, 3] is sequence }}|'60 '{{ "foo" is sequence }}|'61 '{{ 42 is sequence }}'62 )63 assert tmpl.render() == 'True|True|False'6465 def test_upper(self):66 tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}')67 assert tmpl.render() == 'True|False'6869 def test_sameas(self):70 tmpl = env.from_string('{{ foo is sameas false }}|'71 '{{ 0 is sameas false }}')72 assert tmpl.render(foo=False) == 'True|False'7374 def test_no_paren_for_arg1(self):75 tmpl = env.from_string('{{ foo is sameas none }}')76 assert tmpl.render(foo=None) == 'True'7778 def test_escaped(self):79 env = Environment(autoescape=True)80 tmpl = env.from_string('{{ x is escaped }}|{{ y is escaped }}')81 assert tmpl.render(x='foo', y=Markup('foo')) == 'False|True'828384def suite():85 suite = unittest.TestSuite()86 suite.addTest(unittest.makeSuite(TestsTestCase))87 return suite