test_tests.py
This file
Path
tests/test_tests.py
233 lines · 7.7 KiB · Python
Last changed by
Merge pull request #1391 from pallets/markupsafe-importsDavid Lordbefore adoptiona9b06f4
History of this fileTake it
The walk stopped after 200 commits: lines older than 5d33f67 point at it.
Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 1why, one step back1import pytestMerge pull request #1391 from pallets/markupsafe-importsDavid Lordbefore adoptiona9b06f4
line 2why, one step back2from markupsafe import MarkupMerge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 3why, one step back3Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 4why, one step back4from jinja2 import EnvironmentMerge pull request #1383 from pallets/test-decoratorsDavid Lordbefore adoptionbeabf30
lines 5–6why, one step back5from jinja2 import TemplateAssertionError6from jinja2 import TemplateRuntimeErrorMerge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 7why, one step back7Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 8why, one step back8Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 9–11why, one step back9class MyDict(dict):10 pass11Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 12why, one step back12Merge pull request #1136 from pallets/drop-python2David Lordbefore adoption3915eb5
line 13why, one step back13class TestTestsCase:Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 14why, one step back14 def test_defined(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 15–16why, one step back15 tmpl = env.from_string("{{ missing is defined }}|{{ true is defined }}")16 assert tmpl.render() == "False|True"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 17–18why, one step back1718 def test_even(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 19–20why, one step back19 tmpl = env.from_string("""{{ 1 is even }}|{{ 2 is even }}""")20 assert tmpl.render() == "False|True"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 21–22why, one step back2122 def test_odd(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 23–24why, one step back23 tmpl = env.from_string("""{{ 1 is odd }}|{{ 2 is odd }}""")24 assert tmpl.render() == "True|False"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 25–26why, one step back2526 def test_lower(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 27–28why, one step back27 tmpl = env.from_string("""{{ "foo" is lower }}|{{ "FOO" is lower }}""")28 assert tmpl.render() == "True|False"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 29–30why, one step back2930 # Test type checksMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 31–112why, one step back31 @pytest.mark.parametrize(32 "op,expect",33 (34 ("none is none", True),35 ("false is none", False),36 ("true is none", False),37 ("42 is none", False),38 ("none is true", False),39 ("false is true", False),40 ("true is true", True),41 ("0 is true", False),42 ("1 is true", False),43 ("42 is true", False),44 ("none is false", False),45 ("false is false", True),46 ("true is false", False),47 ("0 is false", False),48 ("1 is false", False),49 ("42 is false", False),50 ("none is boolean", False),51 ("false is boolean", True),52 ("true is boolean", True),53 ("0 is boolean", False),54 ("1 is boolean", False),55 ("42 is boolean", False),56 ("0.0 is boolean", False),57 ("1.0 is boolean", False),58 ("3.14159 is boolean", False),59 ("none is integer", False),60 ("false is integer", False),61 ("true is integer", False),62 ("42 is integer", True),63 ("3.14159 is integer", False),64 ("(10 ** 100) is integer", True),65 ("none is float", False),66 ("false is float", False),67 ("true is float", False),68 ("42 is float", False),69 ("4.2 is float", True),70 ("(10 ** 100) is float", False),71 ("none is number", False),72 ("false is number", True),73 ("true is number", True),74 ("42 is number", True),75 ("3.14159 is number", True),76 ("complex is number", True),77 ("(10 ** 100) is number", True),78 ("none is string", False),79 ("false is string", False),80 ("true is string", False),81 ("42 is string", False),82 ('"foo" is string', True),83 ("none is sequence", False),84 ("false is sequence", False),85 ("42 is sequence", False),86 ('"foo" is sequence', True),87 ("[] is sequence", True),88 ("[1, 2, 3] is sequence", True),89 ("{} is sequence", True),90 ("none is mapping", False),91 ("false is mapping", False),92 ("42 is mapping", False),93 ('"foo" is mapping', False),94 ("[] is mapping", False),95 ("{} is mapping", True),96 ("mydict is mapping", True),97 ("none is iterable", False),98 ("false is iterable", False),99 ("42 is iterable", False),100 ('"foo" is iterable', True),101 ("[] is iterable", True),102 ("{} is iterable", True),103 ("range(5) is iterable", True),104 ("none is callable", False),105 ("false is callable", False),106 ("42 is callable", False),107 ('"foo" is callable', False),108 ("[] is callable", False),109 ("{} is callable", False),110 ("range is callable", True),111 ),112 )Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 113why, one step back113 def test_types(self, env, op, expect):Merge pull request #1136 from pallets/drop-python2David Lordbefore adoption3915eb5
line 114why, one step back114 t = env.from_string(f"{{{{ {op} }}}}")Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 115–118why, one step back115 assert t.render(mydict=MyDict(), complex=complex(1, 2)) == str(expect)116117 def test_upper(self, env):118 tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}')Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 119why, one step back119 assert tmpl.render() == "True|False"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 120–122why, one step back120121 def test_equalto(self, env):122 tmpl = env.from_string(Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 123–125why, one step back123 "{{ foo is eq 12 }}|"124 "{{ foo is eq 0 }}|"125 "{{ foo is eq (3 * 4) }}|"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 126–128why, one step back126 '{{ bar is eq "baz" }}|'127 '{{ bar is eq "zab" }}|'128 '{{ bar is eq ("ba" + "z") }}|'Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 129–130why, one step back129 "{{ bar is eq bar }}|"130 "{{ bar is eq foo }}"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 131why, one step back131 )Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 132–135why, one step back132 assert (133 tmpl.render(foo=12, bar="baz")134 == "True|False|True|True|False|True|True|False"135 )Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 136why, one step back136Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 137–153why, one step back137 @pytest.mark.parametrize(138 "op,expect",139 (140 ("eq 2", True),141 ("eq 3", False),142 ("ne 3", True),143 ("ne 2", False),144 ("lt 3", True),145 ("lt 2", False),146 ("le 2", True),147 ("le 1", False),148 ("gt 1", True),149 ("gt 2", False),150 ("ge 2", True),151 ("ge 3", False),152 ),153 )Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 154why, one step back154 def test_compare_aliases(self, env, op, expect):Merge pull request #1136 from pallets/drop-python2David Lordbefore adoption3915eb5
line 155why, one step back155 t = env.from_string(f"{{{{ 2 is {op} }}}}")Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 156–158why, one step back156 assert t.render() == str(expect)157158 def test_sameas(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 159–160why, one step back159 tmpl = env.from_string("{{ foo is sameas false }}|{{ 0 is sameas false }}")160 assert tmpl.render(foo=False) == "True|False"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 161–162why, one step back161162 def test_no_paren_for_arg1(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 163–164why, one step back163 tmpl = env.from_string("{{ foo is sameas none }}")164 assert tmpl.render(foo=None) == "True"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 165–167why, one step back165166 def test_escaped(self, env):167 env = Environment(autoescape=True)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 168–169why, one step back168 tmpl = env.from_string("{{ x is escaped }}|{{ y is escaped }}")169 assert tmpl.render(x="foo", y=Markup("foo")) == "False|True"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 170–171why, one step back170171 def test_greaterthan(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 172–173why, one step back172 tmpl = env.from_string("{{ 1 is greaterthan 0 }}|{{ 0 is greaterthan 1 }}")173 assert tmpl.render() == "True|False"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 174–175why, one step back174175 def test_lessthan(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 176–177why, one step back176 tmpl = env.from_string("{{ 0 is lessthan 1 }}|{{ 1 is lessthan 0 }}")177 assert tmpl.render() == "True|False"Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 178–180why, one step back178179 def test_multiple_tests(self):180 items = []Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 181why, one step back181Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 182–184why, one step back182 def matching(x, y):183 items.append((x, y))184 return FalseMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 185why, one step back185Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
line 186why, one step back186 env = Environment()Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 187–196why, one step back187 env.tests["matching"] = matching188 tmpl = env.from_string(189 "{{ 'us-west-1' is matching '(us-east-1|ap-northeast-1)'"190 " or 'stage' is matching '(dev|stage)' }}"191 )192 assert tmpl.render() == "False"193 assert items == [194 ("us-west-1", "(us-east-1|ap-northeast-1)"),195 ("stage", "(dev|stage)"),196 ]Merge pull request #1105 from areebbeigh/issue-1102David Lordbefore adoption5d33f67
lines 197–198why, one step back197198 def test_in(self, env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 199–210why, one step back199 tmpl = env.from_string(200 '{{ "o" is in "foo" }}|'201 '{{ "foo" is in "foo" }}|'202 '{{ "b" is in "foo" }}|'203 "{{ 1 is in ((1, 2)) }}|"204 "{{ 3 is in ((1, 2)) }}|"205 "{{ 1 is in [1, 2] }}|"206 "{{ 3 is in [1, 2] }}|"207 '{{ "foo" is in {"foo": 1}}}|'208 '{{ "baz" is in {"bar": 1}}}'209 )210 assert tmpl.render() == "True|True|False|True|False|True|False|True|False"Merge pull request #1383 from pallets/test-decoratorsDavid Lordbefore adoptionbeabf30
lines 211–233why, one step back211212213def test_name_undefined(env):214 with pytest.raises(TemplateAssertionError, match="No test named 'f'"):215 env.from_string("{{ x is f }}")216217218def test_name_undefined_in_if(env):219 t = env.from_string("{% if x is defined %}{{ x is f }}{% endif %}")220 assert t.render() == ""221222 with pytest.raises(TemplateRuntimeError, match="No test named 'f'"):223 t.render(x=1)224225226def test_is_filter(env):227 assert env.call_test("filter", "title")228 assert not env.call_test("filter", "bad-name")229230231def test_is_test(env):232 assert env.call_test("test", "number")233 assert not env.call_test("test", "bad-name")