test_debug.py
This file
Path
tests/test_debug.py
116 lines · 3.6 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
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 adoption793ddd4
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 adoption793ddd4
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 adoption793ddd4
lines 17–21why, one step back17 return Environment(loader=filesystem_loader)181920class TestDebug(object):21 def assert_traceback_matches(self, callback, expected_tb):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 22why, one step back22 with pytest.raises(Exception) as exc_info:Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 23–24why, one step back23 callback()24Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 25–31why, one step back25 tb = format_exception(exc_info.type, exc_info.value, exc_info.tb)26 m = re.search(expected_tb.strip(), "".join(tb))27 assert m is not None, "Traceback did not match:\n\n%s\nexpected:\n%s" % (28 "".join(tb),29 expected_tb,30 )31Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 32–34why, one step back32 def test_runtime_error(self, fs_env):33 def test():34 tmpl.render(fail=lambda: 1 / 0)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 35–39why, one step back3536 tmpl = fs_env.get_template("broken.html")37 self.assert_traceback_matches(38 test,39 r"""Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 40–44why, one step back40 File ".*?broken.html", line 2, in (top-level template code|<module>)41 \{\{ fail\(\) \}\}42 File ".*debug?.pyc?", line \d+, in <lambda>43 tmpl\.render\(fail=lambda: 1 / 0\)44ZeroDivisionError: (int(eger)? )?division (or modulo )?by zeroMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 45–46why, one step back45""",46 )Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 47–48why, one step back4748 def test_syntax_error(self, fs_env):Merge pull request #1112 from pallets/include-syntax-error-sourceDavid Lordbefore adoption28f12c0
lines 49–51why, one step back49 # The trailing .*? is for PyPy 2 and 3, which don't seem to50 # clear the exception's original traceback, leaving the syntax51 # error in the middle of other compiler frames.Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 52–54why, one step back52 self.assert_traceback_matches(53 lambda: fs_env.get_template("syntaxerror.html"),54 """(?sm)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 55why, one step back55 File ".*?syntaxerror.html", line 4, in (template|<module>)Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 56why, one step back56 \\{% endif %\\}.*?Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 57why, one step back57(jinja2\\.exceptions\\.)?TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja \Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 58–61why, one step back58was looking for the following tags: 'endfor' or 'else'. The innermost block that needs \59to be closed is 'for'.60 """,61 )Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 62–64why, one step back6263 def test_regular_syntax_error(self, fs_env):64 def test():Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 65–69why, one step back65 raise TemplateSyntaxError("wtf", 42)6667 self.assert_traceback_matches(68 test,69 r"""Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 70why, one step back70 File ".*debug.pyc?", line \d+, in testMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 71why, one step back71 raise TemplateSyntaxError\("wtf", 42\)Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 72why, one step back72(jinja2\.exceptions\.)?TemplateSyntaxError: wtfMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 73–74why, one step back73 line 42""",74 )Merge pull request #1117 from nvllsvm/fix_exc_pickleDavid Lordbefore adoption8342180
lines 75–80why, one step back7576 def test_pickleable_syntax_error(self, fs_env):77 original = TemplateSyntaxError("bad template", 42, "test", "test.txt")78 unpickled = pickle.loads(pickle.dumps(original))79 assert str(original) == str(unpickled)80 assert original.name == unpickled.nameMerge pull request #1112 from pallets/include-syntax-error-sourceDavid Lordbefore adoption28f12c0
lines 81–82why, one step back8182 def test_include_syntax_error_source(self, filesystem_loader):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 83–90why, one step back83 e = Environment(84 loader=ChoiceLoader(85 [86 filesystem_loader,87 DictLoader({"inc": "a\n{% include 'syntaxerror.html' %}\nb"}),88 ]89 )90 )Merge pull request #1112 from pallets/include-syntax-error-sourceDavid Lordbefore adoption28f12c0
lines 91–96why, one step back91 t = e.get_template("inc")9293 with pytest.raises(TemplateSyntaxError) as exc_info:94 t.render()9596 assert exc_info.value.source is not NoneMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 97–98why, one step back9798 def test_local_extraction(self):Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
lines 99–100why, one step back99 from jinja2.debug import get_template_locals100 from jinja2.runtime import missingMerge pull request #673 from MrSenko/get_corresponding_lineno_tracebackDavid Lordbefore adoption5dcc676
line 101why, one step back101Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 102–113why, one step back102 locals = get_template_locals(103 {104 "l_0_foo": 42,105 "l_1_foo": 23,106 "l_2_foo": 13,107 "l_0_bar": 99,108 "l_1_bar": missing,109 "l_0_baz": missing,110 }111 )112 assert locals == {"foo": 13, "bar": 99}113Merge pull request #673 from MrSenko/get_corresponding_lineno_tracebackDavid Lordbefore adoption5dcc676
line 114why, one step back114 def test_get_corresponding_lineno_traceback(self, fs_env):Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 115why, one step back115 tmpl = fs_env.get_template("test.html")Merge pull request #673 from MrSenko/get_corresponding_lineno_tracebackDavid Lordbefore adoption5dcc676
line 116why, one step back116 assert tmpl.get_corresponding_lineno(1) == 1