-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-121790: Fix interactive console initialization #121793
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
Changes from all commits
e3f9cae
9a24df1
964de70
a952374
7b1fc47
1732c5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,10 +517,7 @@ def register_readline(): | |
pass | ||
|
||
if readline.get_current_history_length() == 0: | ||
try: | ||
from _pyrepl.main import CAN_USE_PYREPL | ||
except ImportError: | ||
CAN_USE_PYREPL = False | ||
Comment on lines
-520
to
-523
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simplify this here because in the current state of the code there is no reason for this import to ever fail. |
||
from _pyrepl.main import CAN_USE_PYREPL | ||
# If no history was loaded, default to .python_history, | ||
# or PYTHON_HISTORY. | ||
# The guard is necessary to avoid doubling history size at | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
"""Test the interactive interpreter.""" | ||
|
||
import os | ||
import select | ||
import subprocess | ||
import sys | ||
import unittest | ||
from textwrap import dedent | ||
from test import support | ||
from test.support import cpython_only, has_subprocess_support, SuppressCrashReport | ||
from test.support.script_helper import assert_python_failure, kill_python, assert_python_ok | ||
from test.support import ( | ||
cpython_only, | ||
has_subprocess_support, | ||
os_helper, | ||
SuppressCrashReport, | ||
SHORT_TIMEOUT, | ||
) | ||
from test.support.script_helper import kill_python | ||
from test.support.import_helper import import_module | ||
|
||
try: | ||
import pty | ||
except ImportError: | ||
pty = None | ||
|
||
|
||
if not has_subprocess_support: | ||
raise unittest.SkipTest("test module requires subprocess") | ||
|
@@ -195,9 +207,56 @@ def bar(x): | |
expected = "(30, None, [\'def foo(x):\\n\', \' return x + 1\\n\', \'\\n\'], \'<stdin>\')" | ||
self.assertIn(expected, output, expected) | ||
|
||
def test_asyncio_repl_no_tty_fails(self): | ||
assert assert_python_failure("-m", "asyncio") | ||
Comment on lines
-198
to
-199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test used to be |
||
def test_asyncio_repl_reaches_python_startup_script(self): | ||
with os_helper.temp_dir() as tmpdir: | ||
script = os.path.join(tmpdir, "pythonstartup.py") | ||
with open(script, "w") as f: | ||
f.write("print('pythonstartup done!')" + os.linesep) | ||
f.write("exit(0)" + os.linesep) | ||
|
||
env = os.environ.copy() | ||
env["PYTHONSTARTUP"] = script | ||
subprocess.check_call( | ||
[sys.executable, "-m", "asyncio"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
env=env, | ||
timeout=SHORT_TIMEOUT, | ||
) | ||
|
||
@unittest.skipUnless(pty, "requires pty") | ||
def test_asyncio_repl_is_ok(self): | ||
m, s = pty.openpty() | ||
cmd = [sys.executable, "-m", "asyncio"] | ||
proc = subprocess.Popen( | ||
cmd, | ||
stdin=s, | ||
stdout=s, | ||
stderr=s, | ||
text=True, | ||
close_fds=True, | ||
env=os.environ, | ||
) | ||
os.close(s) | ||
os.write(m, b"await asyncio.sleep(0)\n") | ||
os.write(m, b"exit()\n") | ||
output = [] | ||
while select.select([m], [], [], SHORT_TIMEOUT)[0]: | ||
try: | ||
data = os.read(m, 1024).decode("utf-8") | ||
if not data: | ||
break | ||
except OSError: | ||
break | ||
output.append(data) | ||
os.close(m) | ||
try: | ||
exit_code = proc.wait(timeout=SHORT_TIMEOUT) | ||
except subprocess.TimeoutExpired: | ||
proc.kill() | ||
exit_code = proc.wait() | ||
|
||
self.assertEqual(exit_code, 0) | ||
|
||
class TestInteractiveModeSyntaxErrors(unittest.TestCase): | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.