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
Provenance
- Commit
41d6f71- Tree
5a8dcf1- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
4254936
3 files changed+89 added−62 removed
modified:jinja2/testsuite/__init__.py+2 added-1 removed
42 unmodified lines43 return self.assertRaises(*args, **kwargs)44 45 46 def 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 suitemodified:jinja2/testsuite/filters.py-61 removed
14 unmodified lines15 16 env = Environment()17 18 19-CAPITALIZE = '''{{ "foo bar"|capitalize }}'''20-CENTER = '''{{ "foo"|center(9) }}'''21-DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\22-{{ false|default('no', true) }}|{{ given|default("no") }}'''23-DICTSORT = '''{{ foo|dictsort }}|\24-{{ foo|dictsort(true) }}|\25-{{ foo|dictsort(false, 'value') }}'''26-BATCH = '''{{ foo|batch(3)|list }}|{{ foo|batch(3, 'X')|list }}'''27-SLICE = '''{{ foo|slice(3)|list }}|{{ foo|slice(3, 'X')|list }}'''28-ESCAPE = '''{{ '<">&'|escape }}'''29-STRIPTAGS = '''{{ foo|striptags }}'''30-FILESIZEFORMAT = '{{ 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) }}'40-FIRST = '''{{ foo|first }}'''41-FLOAT = '''{{ "42"|float }}|{{ "ajsghasjgd"|float }}|{{ "32.32"|float }}'''42-FORMAT = '''{{ "%s|%s"|format("a", "b") }}'''43-INDENT = '''{{ foo|indent(2) }}|{{ foo|indent(2, true) }}'''44-INT = '''{{ "42"|int }}|{{ "ajsghasjgd"|int }}|{{ "32.32"|int }}'''45-JOIN = '''{{ [1, 2, 3]|join("|") }}'''46-LAST = '''{{ foo|last }}'''47-LENGTH = '''{{ "hello world"|length }}'''48-LOWER = '''{{ "FOO"|lower }}'''49-PPRINT = '''{{ data|pprint }}'''50-RANDOM = '''{{ seq|random }}'''51-REVERSE = '''{{ "foobar"|reverse|join }}|{{ [1, 2, 3]|reverse|list }}'''52-STRING = '''{{ range(10)|string }}'''53-TITLE = '''{{ "foo bar"|title }}'''54-TRIM = '''{{ " foo "|trim }}'''55-TRUNCATE = '''{{ data|truncate(15, true, ">>>") }}|\56-{{ data|truncate(15, false, ">>>") }}|\57-{{ smalldata|truncate(15) }}'''58-UPPER = '''{{ "foo"|upper }}'''59-URLIZE = '''{{ "foo http://www.example.com/ bar"|urlize }}'''60-WORDCOUNT = '''{{ "foo bar baz"|wordcount }}'''61-BLOCK = '''{% filter lower|escape %}<HEHE>{% endfilter %}'''62-CHAINING = '''{{ ['<foo>', '<bar>']|first|upper|escape }}'''63-SUM = '''{{ [1, 2, 3, 4, 5, 6]|sum }}'''64-ABS = '''{{ -1|abs }}|{{ 1|abs }}'''65-ROUND = '''{{ 2.7|round }}|{{ 2.1|round }}|\66-{{ 2.1234|round(2, 'floor') }}|{{ 2.1|round(0, 'ceil') }}'''67-XMLATTR = '''{{ {'foo': 42, 'bar': 23, 'fish': none,68-'spam': missing, 'blub:blub': '<?>'}|xmlattr }}'''69-SORT1 = '''{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}'''70-GROUPBY = '''{% 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 %}'''76-FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''77-SORT2 = '''{{ ['foo', 'Bar', 'blah']|sort }}'''78-79-19 class FilterTestCase(JinjaTestCase):20 21 def test_capitalize(self):22 tmpl = env.from_string('{{ "foo bar"|capitalize }}')258 unmodified linesadded:jinja2/testsuite/tests.py+87 added
1+# -*- coding: utf-8 -*-2+"""3+ jinja2.testsuite.tests4+ ~~~~~~~~~~~~~~~~~~~~~~5+6+ Who tests the tests?7+8+ :copyright: (c) 2010 by the Jinja Team.9+ :license: BSD, see LICENSE for more details.10+"""11+import unittest12+from jinja2.testsuite import JinjaTestCase13+14+from jinja2 import Markup, Environment15+16+env = Environment()17+18+19+class TestsTestCase(JinjaTestCase):20+21+ def test_defined(self):22+ tmpl = env.from_string('{{ missing is defined }}|{{ true is defined }}')23+ assert tmpl.render() == 'False|True'24+25+ def test_even(self):26+ tmpl = env.from_string('''{{ 1 is even }}|{{ 2 is even }}''')27+ assert tmpl.render() == 'False|True'28+29+ def test_odd(self):30+ tmpl = env.from_string('''{{ 1 is odd }}|{{ 2 is odd }}''')31+ assert tmpl.render() == 'True|False'32+33+ def test_lower(self):34+ tmpl = env.from_string('''{{ "foo" is lower }}|{{ "FOO" is lower }}''')35+ assert tmpl.render() == 'True|False'36+37+ 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+ ]56+57+ 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'64+65+ def test_upper(self):66+ tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}')67+ assert tmpl.render() == 'True|False'68+69+ 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'73+74+ def test_no_paren_for_arg1(self):75+ tmpl = env.from_string('{{ foo is sameas none }}')76+ assert tmpl.render(foo=None) == 'True'77+78+ 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'82+83+84+def suite():85+ suite = unittest.TestSuite()86+ suite.addTest(unittest.makeSuite(TestsTestCase))87+ return suite