test_debug.py
This file
Path
tests/test_debug.py
117 lines · 3.6 KiB · Python
Last changed by
Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
History of this fileTake it
The walk stopped after 200 commits: lines older than 6b8a14a point at it.
Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
line 1why, one step back1# -*- coding: utf-8 -*-Merge pull request #1117 from nvllsvm/fix_exc_pickleDavid Lordbefore adoption8342180
line 2why, one step back2import pickleMerge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 3–5why, one step back3import re4from traceback import format_exception5Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 6–7why, one step back6import pytest7Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
lines 8–11why, one step back8from jinja2 import ChoiceLoader9from jinja2 import DictLoader10from jinja2 import Environment11from jinja2 import TemplateSyntaxErrorMerge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 12–15why, one step back121314@pytest.fixture15def fs_env(filesystem_loader):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 16why, one step back16 """returns a new environment."""Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 17–22why, one step back17 return Environment(loader=filesystem_loader)181920@pytest.mark.debug21class TestDebug(object):22 def assert_traceback_matches(self, callback, expected_tb):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 23why, one step back23 with pytest.raises(Exception) as exc_info:Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 24–25why, one step back24 callback()25Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 26–32why, one step back26 tb = format_exception(exc_info.type, exc_info.value, exc_info.tb)27 m = re.search(expected_tb.strip(), "".join(tb))28 assert m is not None, "Traceback did not match:\n\n%s\nexpected:\n%s" % (29 "".join(tb),30 expected_tb,31 )32Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 33–35why, one step back33 def test_runtime_error(self, fs_env):34 def test():35 tmpl.render(fail=lambda: 1 / 0)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 36–40why, one step back3637 tmpl = fs_env.get_template("broken.html")38 self.assert_traceback_matches(39 test,40 r"""Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 41–45why, one step back41 File ".*?broken.html", line 2, in (top-level template code|<module>)42 \{\{ fail\(\) \}\}43 File ".*debug?.pyc?", line \d+, in <lambda>44 tmpl\.render\(fail=lambda: 1 / 0\)45ZeroDivisionError: (int(eger)? )?division (or modulo )?by zeroMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 46–47why, one step back46""",47 )Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 48–49why, one step back4849 def test_syntax_error(self, fs_env):Merge pull request #1112 from pallets/include-syntax-error-sourceDavid Lordbefore adoption28f12c0
lines 50–52why, one step back50 # The trailing .*? is for PyPy 2 and 3, which don't seem to51 # clear the exception's original traceback, leaving the syntax52 # error in the middle of other compiler frames.Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 53–55why, one step back53 self.assert_traceback_matches(54 lambda: fs_env.get_template("syntaxerror.html"),55 """(?sm)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
line 56why, one step back56 File ".*?syntaxerror.html", line 4, in (template|<module>)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 57why, one step back57 \\{% endif %\\}.*?Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 58why, one step back58(jinja2\\.exceptions\\.)?TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja \Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 59–62why, one step back59was looking for the following tags: 'endfor' or 'else'. The innermost block that needs \60to be closed is 'for'.61 """,62 )Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 63–65why, one step back6364 def test_regular_syntax_error(self, fs_env):65 def test():Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 66–70why, one step back66 raise TemplateSyntaxError("wtf", 42)6768 self.assert_traceback_matches(69 test,70 r"""Merge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
line 71why, one step back71 File ".*debug.pyc?", line \d+, in testMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 72why, one step back72 raise TemplateSyntaxError\("wtf", 42\)Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 73why, one step back73(jinja2\.exceptions\.)?TemplateSyntaxError: wtfMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 74–75why, one step back74 line 42""",75 )Merge pull request #1117 from nvllsvm/fix_exc_pickleDavid Lordbefore adoption8342180
lines 76–81why, one step back7677 def test_pickleable_syntax_error(self, fs_env):78 original = TemplateSyntaxError("bad template", 42, "test", "test.txt")79 unpickled = pickle.loads(pickle.dumps(original))80 assert str(original) == str(unpickled)81 assert original.name == unpickled.nameMerge pull request #1112 from pallets/include-syntax-error-sourceDavid Lordbefore adoption28f12c0
lines 82–83why, one step back8283 def test_include_syntax_error_source(self, filesystem_loader):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 84–91why, one step back84 e = Environment(85 loader=ChoiceLoader(86 [87 filesystem_loader,88 DictLoader({"inc": "a\n{% include 'syntaxerror.html' %}\nb"}),89 ]90 )91 )Merge pull request #1112 from pallets/include-syntax-error-sourceDavid Lordbefore adoption28f12c0
lines 92–97why, one step back92 t = e.get_template("inc")9394 with pytest.raises(TemplateSyntaxError) as exc_info:95 t.render()9697 assert exc_info.value.source is not NoneMerge branch '2.9-maintenance'Armin Ronacherbefore adoption6b8a14a
lines 98–99why, one step back9899 def test_local_extraction(self):Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
lines 100–101why, one step back100 from jinja2.debug import get_template_locals101 from jinja2.runtime import missingMerge pull request #673 from MrSenko/get_corresponding_lineno_tracebackDavid Lordbefore adoption5dcc676
line 102why, one step back102Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 103–114why, one step back103 locals = get_template_locals(104 {105 "l_0_foo": 42,106 "l_1_foo": 23,107 "l_2_foo": 13,108 "l_0_bar": 99,109 "l_1_bar": missing,110 "l_0_baz": missing,111 }112 )113 assert locals == {"foo": 13, "bar": 99}114Merge pull request #673 from MrSenko/get_corresponding_lineno_tracebackDavid Lordbefore adoption5dcc676
line 115why, one step back115 def test_get_corresponding_lineno_traceback(self, fs_env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 116why, one step back116 tmpl = fs_env.get_template("test.html")Merge pull request #673 from MrSenko/get_corresponding_lineno_tracebackDavid Lordbefore adoption5dcc676
line 117why, one step back117 assert tmpl.get_corresponding_lineno(1) == 1