# jinja2-main / tests / test_tests.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94``` ```# -*- coding: utf-8 -*- """ unit test for the test functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2009 by the Jinja Team. :license: BSD, see LICENSE for more details. """ from jinja2 import Environment, Markup env = Environment() DEFINED = '''{{ missing is defined }}|{{ true is defined }}''' EVEN = '''{{ 1 is even }}|{{ 2 is even }}''' LOWER = '''{{ "foo" is lower }}|{{ "FOO" is lower }}''' ODD = '''{{ 1 is odd }}|{{ 2 is odd }}''' SEQUENCE = '''{{ [1, 2, 3] is sequence }}|\ {{ "foo" is sequence }}|\ {{ 42 is sequence }}''' UPPER = '''{{ "FOO" is upper }}|{{ "foo" is upper }}''' SAMEAS = '''{{ foo is sameas false }}|{{ 0 is sameas false }}''' NOPARENFORARG1 = '''{{ foo is sameas none }}''' TYPECHECKS = '''\ {{ 42 is undefined }} {{ 42 is defined }} {{ 42 is none }} {{ none is none }} {{ 42 is number }} {{ 42 is string }} {{ "foo" is string }} {{ "foo" is sequence }} {{ [1] is sequence }} {{ range is callable }} {{ 42 is callable }} {{ range(5) is iterable }}''' def test_defined(): tmpl = env.from_string(DEFINED) assert tmpl.render() == 'False|True' def test_even(): tmpl = env.from_string(EVEN) assert tmpl.render() == 'False|True' def test_odd(): tmpl = env.from_string(ODD) assert tmpl.render() == 'True|False' def test_lower(): tmpl = env.from_string(LOWER) assert tmpl.render() == 'True|False' def test_typechecks(): tmpl = env.from_string(TYPECHECKS) assert tmpl.render() == '' def test_sequence(): tmpl = env.from_string(SEQUENCE) assert tmpl.render() == 'True|True|False' def test_upper(): tmpl = env.from_string(UPPER) assert tmpl.render() == 'True|False' def test_sameas(): tmpl = env.from_string(SAMEAS) assert tmpl.render(foo=False) == 'True|False' def test_typechecks(): tmpl = env.from_string(TYPECHECKS) assert tmpl.render() == ( 'False\nTrue\nFalse\nTrue\nTrue\nFalse\n' 'True\nTrue\nTrue\nTrue\nFalse\nTrue' ) def test_no_paren_for_arg1(): tmpl = env.from_string(NOPARENFORARG1) assert tmpl.render(foo=None) == 'True' def test_escaped(): env = Environment(autoescape=True) tmpl = env.from_string('{{ x is escaped }}|{{ y is escaped }}') assert tmpl.render(x='foo', y=Markup('foo')) == 'False|True' ```