Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2021 18:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
def test_traceback_specialization_with_syntax_error(self):
source = textwrap.dedent("""\
def func(x, y):
return x / y
bytecode = compile(source, TESTFN, "exec")
with open(TESTFN, "w") as file:
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