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 fileTake 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 back1# -*- coding: utf-8 -*-2import pytest3Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
lines 4–5why, one step back4from jinja2 import Environment5from jinja2 import MarkupMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 6why, one step back6Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 7why, one step back7Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252
lines 8–9why, one step back8class MyDict(dict):9 passMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 10why, one step back10Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 11why, one step back11Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 12–13why, one step back12class TestTestsCase(object):13 def test_defined(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 14–15why, one step back14 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 back1617 def test_even(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 18–19why, one step back18 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 back2021 def test_odd(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 22–23why, one step back22 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 back2425 def test_lower(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 26–27why, one step back26 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 back28Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252
line 29why, one step back29 # Test type checksMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 30–111why, one step back30 @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 back112 def test_types(self, env, op, expect):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 113why, one step back113 t = env.from_string("{{{{ {op} }}}}".format(op=op))Merge pull request #824 from dagwieers/new-type-testsDavid Lordbefore adoption0b9d252
lines 114–115why, one step back114 assert t.render(mydict=MyDict(), complex=complex(1, 2)) == str(expect)115Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 116–117why, one step back116 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 back118 assert tmpl.render() == "True|False"Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 119–120why, one step back119120 def test_equalto(self, env):Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4
line 121why, one step back121 tmpl = env.from_string(Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 122–124why, one step back122 "{{ 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 back125 '{{ 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 back128 "{{ bar is eq bar }}|"129 "{{ bar is eq foo }}"Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4
line 130why, one step back130 )Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 131–134why, one step back131 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 back135Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 136–152why, one step back136 @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 back153 def test_compare_aliases(self, env, op, expect):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 154why, one step back154 t = env.from_string("{{{{ 2 is {op} }}}}".format(op=op))Merge pull request #665 from pallets/operator-testsDavid Lordbefore adoptionca1abd4
line 155why, one step back155 assert t.render() == str(expect)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 156–157why, one step back156157 def test_sameas(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 158–159why, one step back158 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 back160161 def test_no_paren_for_arg1(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 162–163why, one step back162 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 back164165 def test_escaped(self, env):166 env = Environment(autoescape=True)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 167–168why, one step back167 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 back169170 def test_greaterthan(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 171–172why, one step back171 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 back173174 def test_lessthan(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 175–176why, one step back175 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 back177178 def test_multiple_tests(self):179 items = []Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 180why, one step back180Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 181–183why, one step back181 def matching(x, y):182 items.append((x, y))183 return FalseMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 184why, one step back184Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 185why, one step back185 env = Environment()Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 186–195why, one step back186 env.tests["matching"] = matching187 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 back196197 def test_in(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 198–209why, one step back198 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"