test_tests.py
This file
Path
tests/test_tests.py
104 lines · 3.5 KiB · Python
Last changed by
Merge branch 'lkarthee-pytest_migration'Markus Unterwaditzerbefore adoption1c5f1e8
History of this fileTake it
Merge branch 'lkarthee-pytest_migration'Markus Unterwaditzerbefore adoption1c5f1e8
lines 1–104why, one step back1# -*- 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 pytest1213from jinja2 import Markup, Environment141516@pytest.mark.test_tests17class TestTestsCase():1819 def test_defined(self, env):20 tmpl = env.from_string('{{ missing is defined }}|'21 '{{ true is defined }}')22 assert tmpl.render() == 'False|True'2324 def test_even(self, env):25 tmpl = env.from_string('''{{ 1 is even }}|{{ 2 is even }}''')26 assert tmpl.render() == 'False|True'2728 def test_odd(self, env):29 tmpl = env.from_string('''{{ 1 is odd }}|{{ 2 is odd }}''')30 assert tmpl.render() == 'True|False'3132 def test_lower(self, env):33 tmpl = env.from_string('''{{ "foo" is lower }}|{{ "FOO" is lower }}''')34 assert tmpl.render() == 'True|False'3536 def test_typechecks(self, env):37 tmpl = env.from_string('''38 {{ 42 is undefined }}39 {{ 42 is defined }}40 {{ 42 is none }}41 {{ none is none }}42 {{ 42 is number }}43 {{ 42 is string }}44 {{ "foo" is string }}45 {{ "foo" is sequence }}46 {{ [1] is sequence }}47 {{ range is callable }}48 {{ 42 is callable }}49 {{ range(5) is iterable }}50 {{ {} is mapping }}51 {{ mydict is mapping }}52 {{ [] is mapping }}53 {{ 10 is number }}54 {{ (10 ** 100) is number }}55 {{ 3.14159 is number }}56 {{ complex is number }}57 ''')5859 class MyDict(dict):60 pass6162 assert tmpl.render(mydict=MyDict(), complex=complex(1, 2)).split() == [63 'False', 'True', 'False', 'True', 'True', 'False',64 'True', 'True', 'True', 'True', 'False', 'True',65 'True', 'True', 'False', 'True', 'True', 'True', 'True'66 ]6768 def test_sequence(self, env):69 tmpl = env.from_string(70 '{{ [1, 2, 3] is sequence }}|'71 '{{ "foo" is sequence }}|'72 '{{ 42 is sequence }}'73 )74 assert tmpl.render() == 'True|True|False'7576 def test_upper(self, env):77 tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}')78 assert tmpl.render() == 'True|False'7980 def test_equalto(self, env):81 tmpl = env.from_string('{{ foo is equalto 12 }}|'82 '{{ foo is equalto 0 }}|'83 '{{ foo is equalto (3 * 4) }}|'84 '{{ bar is equalto "baz" }}|'85 '{{ bar is equalto "zab" }}|'86 '{{ bar is equalto ("ba" + "z") }}|'87 '{{ bar is equalto bar }}|'88 '{{ bar is equalto foo }}')89 assert tmpl.render(foo=12, bar="baz") \90 == 'True|False|True|True|False|True|True|False'9192 def test_sameas(self, env):93 tmpl = env.from_string('{{ foo is sameas false }}|'94 '{{ 0 is sameas false }}')95 assert tmpl.render(foo=False) == 'True|False'9697 def test_no_paren_for_arg1(self, env):98 tmpl = env.from_string('{{ foo is sameas none }}')99 assert tmpl.render(foo=None) == 'True'100101 def test_escaped(self, env):102 env = Environment(autoescape=True)103 tmpl = env.from_string('{{ x is escaped }}|{{ y is escaped }}')104 assert tmpl.render(x='foo', y=Markup('foo')) == 'False|True'