Skip to content

bpo-46441: Add a regression test for caret position #30720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
stdout=stdout, stderr=stderr,
**kw)

def run_on_interactive_mode(source):
"""Spawn a new Python interpreter, pass the given
input source code from the stdin and return the
result back. If the interpreter exits non-zero, it
raises a ValueError."""

process = spawn_repl()
process.stdin.write(source)
output = kill_python(process)

if process.returncode != 0:
raise ValueError("Process didn't exit properly.")
return output


class TestInteractiveInterpreter(unittest.TestCase):

@cpython_only
Expand Down Expand Up @@ -108,5 +123,23 @@ def test_close_stdin(self):
self.assertIn('before close', output)


class TestInteractiveModeSyntaxErrors(unittest.TestCase):

def test_interactive_syntax_error_correct_line(self):
output = run_on_interactive_mode(dedent("""\
def f():
print(0)
return yield 42
"""))

traceback_lines = output.splitlines()[-4:-1]
expected_lines = [
' return yield 42',
' ^^^^^',
'SyntaxError: invalid syntax'
]
self.assertEqual(traceback_lines, expected_lines)


if __name__ == "__main__":
unittest.main()