This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_traceback_specialization_with_syntax_error(self): | |
source = textwrap.dedent("""\ | |
def func(x, y): | |
return x / y | |
func( | |
1, | |
0 | |
) | |
""") | |
bytecode = compile(source, TESTFN, "exec") | |
with open(TESTFN, "w") as file: | |
file.write(source) | |
self.addCleanup(unlink, TESTFN) | |
func = partial(exec, bytecode) | |
result_lines = self.get_exception(func) | |
lineno_f = bytecode.co_firstlineno | |
expected_error = ( | |
'Traceback (most recent call last):\n' | |
f' File "{__file__}", line {self.callable_line}, in get_exception\n' | |
' callable()\n' | |
' ^^^^^^^^^^\n' | |
f' File "{TESTFN}", line 4, in <module>\n' | |
' func(\n' | |
' ^^^^^\n' | |
f' File "{TESTFN}", line 2, in func\n' | |
' return x / y\n' | |
' ~~^~~' | |
) | |
self.assertEqual(result_lines, expected_error.splitlines()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment