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
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()