Skip to content

Instantly share code, notes, and snippets.

@isidentical
Created July 24, 2021 18:20
Show Gist options
  • Save isidentical/37ab1693d551b678a52626298d99e582 to your computer and use it in GitHub Desktop.
Save isidentical/37ab1693d551b678a52626298d99e582 to your computer and use it in GitHub Desktop.
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