Skip to content
Myr

test_tests.py

This file

Path

tests/test_tests.py

209 lines · 7.0 KiB · Python

Last changed by

remove custom pytest marksDavid Lordbefore adoptiondd5a050

History of this file

Take it

The walk stopped after 200 commits: lines older than 793ddd4 point at it.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 1–3why, one step back
1# -*- coding: utf-8 -*-
2import pytest3

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

lines 4–5why, one step back
4from jinja2 import Environment
5from jinja2 import Markup

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 6why, one step back
6

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 7why, one step back
7

Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252

lines 8–9why, one step back
8class MyDict(dict):
9 pass

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 10why, one step back
10

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 11why, one step back
11

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 12–13why, one step back
12class TestTestsCase(object):
13 def test_defined(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 14–15why, one step back
14 tmpl = env.from_string("{{ missing is defined }}|{{ true is defined }}")
15 assert tmpl.render() == "False|True"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 16–17why, one step back
16
17 def test_even(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 18–19why, one step back
18 tmpl = env.from_string("""{{ 1 is even }}|{{ 2 is even }}""")
19 assert tmpl.render() == "False|True"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 20–21why, one step back
20
21 def test_odd(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 22–23why, one step back
22 tmpl = env.from_string("""{{ 1 is odd }}|{{ 2 is odd }}""")
23 assert tmpl.render() == "True|False"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 24–25why, one step back
24
25 def test_lower(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 26–27why, one step back
26 tmpl = env.from_string("""{{ "foo" is lower }}|{{ "FOO" is lower }}""")
27 assert tmpl.render() == "True|False"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 28why, one step back
28

Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252

line 29why, one step back
29 # Test type checks

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 30–111why, one step back
30 @pytest.mark.parametrize(
31 "op,expect",32 (33 ("none is none", True),34 ("false is none", False),35 ("true is none", False),36 ("42 is none", False),37 ("none is true", False),38 ("false is true", False),39 ("true is true", True),40 ("0 is true", False),41 ("1 is true", False),42 ("42 is true", False),43 ("none is false", False),44 ("false is false", True),45 ("true is false", False),46 ("0 is false", False),47 ("1 is false", False),48 ("42 is false", False),49 ("none is boolean", False),50 ("false is boolean", True),51 ("true is boolean", True),52 ("0 is boolean", False),53 ("1 is boolean", False),54 ("42 is boolean", False),55 ("0.0 is boolean", False),56 ("1.0 is boolean", False),57 ("3.14159 is boolean", False),58 ("none is integer", False),59 ("false is integer", False),60 ("true is integer", False),61 ("42 is integer", True),62 ("3.14159 is integer", False),63 ("(10 ** 100) is integer", True),64 ("none is float", False),65 ("false is float", False),66 ("true is float", False),67 ("42 is float", False),68 ("4.2 is float", True),69 ("(10 ** 100) is float", False),70 ("none is number", False),71 ("false is number", True),72 ("true is number", True),73 ("42 is number", True),74 ("3.14159 is number", True),75 ("complex is number", True),76 ("(10 ** 100) is number", True),77 ("none is string", False),78 ("false is string", False),79 ("true is string", False),80 ("42 is string", False),81 ('"foo" is string', True),82 ("none is sequence", False),83 ("false is sequence", False),84 ("42 is sequence", False),85 ('"foo" is sequence', True),86 ("[] is sequence", True),87 ("[1, 2, 3] is sequence", True),88 ("{} is sequence", True),89 ("none is mapping", False),90 ("false is mapping", False),91 ("42 is mapping", False),92 ('"foo" is mapping', False),93 ("[] is mapping", False),94 ("{} is mapping", True),95 ("mydict is mapping", True),96 ("none is iterable", False),97 ("false is iterable", False),98 ("42 is iterable", False),99 ('"foo" is iterable', True),100 ("[] is iterable", True),101 ("{} is iterable", True),102 ("range(5) is iterable", True),103 ("none is callable", False),104 ("false is callable", False),105 ("42 is callable", False),106 ('"foo" is callable', False),107 ("[] is callable", False),108 ("{} is callable", False),109 ("range is callable", True),110 ),111 )

Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252

line 112why, one step back
112 def test_types(self, env, op, expect):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 113why, one step back
113 t = env.from_string("{{{{ {op} }}}}".format(op=op))

Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252

lines 114–115why, one step back
114 assert t.render(mydict=MyDict(), complex=complex(1, 2)) == str(expect)
115

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 116–117why, one step back
116 def test_upper(self, env):
117 tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}')

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 118why, one step back
118 assert tmpl.render() == "True|False"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 119–120why, one step back
119
120 def test_equalto(self, env):

Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4

line 121why, one step back
121 tmpl = env.from_string(

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 122–124why, one step back
122 "{{ foo is eq 12 }}|"
123 "{{ foo is eq 0 }}|"124 "{{ foo is eq (3 * 4) }}|"

Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4

lines 125–127why, one step back
125 '{{ bar is eq "baz" }}|'
126 '{{ bar is eq "zab" }}|'127 '{{ bar is eq ("ba" + "z") }}|'

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 128–129why, one step back
128 "{{ bar is eq bar }}|"
129 "{{ bar is eq foo }}"

Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4

line 130why, one step back
130 )

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 131–134why, one step back
131 assert (
132 tmpl.render(foo=12, bar="baz")133 == "True|False|True|True|False|True|True|False"134 )

Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4

line 135why, one step back
135

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 136–152why, one step back
136 @pytest.mark.parametrize(
137 "op,expect",138 (139 ("eq 2", True),140 ("eq 3", False),141 ("ne 3", True),142 ("ne 2", False),143 ("lt 3", True),144 ("lt 2", False),145 ("le 2", True),146 ("le 1", False),147 ("gt 1", True),148 ("gt 2", False),149 ("ge 2", True),150 ("ge 3", False),151 ),152 )

Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4

line 153why, one step back
153 def test_compare_aliases(self, env, op, expect):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 154why, one step back
154 t = env.from_string("{{{{ 2 is {op} }}}}".format(op=op))

Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4

line 155why, one step back
155 assert t.render() == str(expect)

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 156–157why, one step back
156
157 def test_sameas(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 158–159why, one step back
158 tmpl = env.from_string("{{ foo is sameas false }}|{{ 0 is sameas false }}")
159 assert tmpl.render(foo=False) == "True|False"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 160–161why, one step back
160
161 def test_no_paren_for_arg1(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 162–163why, one step back
162 tmpl = env.from_string("{{ foo is sameas none }}")
163 assert tmpl.render(foo=None) == "True"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 164–166why, one step back
164
165 def test_escaped(self, env):166 env = Environment(autoescape=True)

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 167–168why, one step back
167 tmpl = env.from_string("{{ x is escaped }}|{{ y is escaped }}")
168 assert tmpl.render(x="foo", y=Markup("foo")) == "False|True"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 169–170why, one step back
169
170 def test_greaterthan(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 171–172why, one step back
171 tmpl = env.from_string("{{ 1 is greaterthan 0 }}|{{ 0 is greaterthan 1 }}")
172 assert tmpl.render() == "True|False"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 173–174why, one step back
173
174 def test_lessthan(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 175–176why, one step back
175 tmpl = env.from_string("{{ 0 is lessthan 1 }}|{{ 1 is lessthan 0 }}")
176 assert tmpl.render() == "True|False"

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 177–179why, one step back
177
178 def test_multiple_tests(self):179 items = []

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 180why, one step back
180

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 181–183why, one step back
181 def matching(x, y):
182 items.append((x, y))183 return False

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 184why, one step back
184

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 185why, one step back
185 env = Environment()

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 186–195why, one step back
186 env.tests["matching"] = matching
187 tmpl = env.from_string(188 "{{ 'us-west-1' is matching '(us-east-1|ap-northeast-1)'"189 " or 'stage' is matching '(dev|stage)' }}"190 )191 assert tmpl.render() == "False"192 assert items == [193 ("us-west-1", "(us-east-1|ap-northeast-1)"),194 ("stage", "(dev|stage)"),195 ]

Add "is in" containment test (#658)Dirk Dbefore adoption7ab79c6

lines 196–197why, one step back
196
197 def test_in(self, env):

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 198–209why, one step back
198 tmpl = env.from_string(
199 '{{ "o" is in "foo" }}|'200 '{{ "foo" is in "foo" }}|'201 '{{ "b" is in "foo" }}|'202 "{{ 1 is in ((1, 2)) }}|"203 "{{ 3 is in ((1, 2)) }}|"204 "{{ 1 is in [1, 2] }}|"205 "{{ 3 is in [1, 2] }}|"206 '{{ "foo" is in {"foo": 1}}}|'207 '{{ "baz" is in {"bar": 1}}}'208 )209 assert tmpl.render() == "True|True|False|True|False|True|False|True|False"