Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
703c1d1
migrating issue to github
diekmann Apr 10, 2017
78c165a
using subprocess.run to run pty.spawn
diekmann Apr 14, 2017
28e918e
move _mock_stdin_stdout to the actual tests
diekmann Apr 14, 2017
6e7f587
Get os.forkpty disabled again.
diekmann Apr 14, 2017
fd61cad
Yes, way less monkey patching.
diekmann Apr 14, 2017
e9b0b8b
Decoupling PtySpawnTestBase and PtyMockingTestBase
diekmann Apr 14, 2017
a42755b
Move PtyMockingTestBase closer to PtyCopyTests
diekmann Apr 14, 2017
7451f97
Tuned class hierarchy
diekmann Apr 14, 2017
b604d83
fix line length and error path of base classes
diekmann Apr 14, 2017
cbe7d14
clarify difference to alternatives
diekmann Apr 14, 2017
8afd1e7
move disable-os.forkpty-code closer to the test
diekmann Apr 14, 2017
2c3498f
cosmetic changes
diekmann Apr 14, 2017
ec58a62
polish
diekmann Apr 14, 2017
0be6c54
let exceptions out and fail the tests
diekmann Apr 14, 2017
250ae50
Pull related code for select mocking tests together
diekmann Apr 14, 2017
7ced6d8
Tune PtyCopyTests
diekmann Apr 14, 2017
528fc5d
unify code comments in PtySpawnTestBase
diekmann Apr 15, 2017
aeb6585
cosmetic changes
diekmann Apr 15, 2017
57876df
Cleanup of terminal setup code
diekmann Apr 15, 2017
2309d69
removed test_eof_echoctl
diekmann Apr 15, 2017
f93de8d
fixed echoing race
diekmann Apr 15, 2017
9cd9425
cleaned OS X workaround comments
diekmann Apr 15, 2017
a7e4753
Removed doc string from test methods.
diekmann Apr 15, 2017
5944764
Fixed comment
diekmann Apr 15, 2017
851c261
[CONTRIBUTING.rst] Added myself to Misc/ACKS
diekmann Jul 28, 2017
5dbc249
added Chris Torek to ACKS
diekmann Jul 28, 2017
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
Prev Previous commit
Next Next commit
unify code comments in PtySpawnTestBase
Better terminology, clearly introducing background/slave.
  • Loading branch information
diekmann committed Jul 28, 2017
commit 528fc5dcc1478927cb1fda28adf649b129f60cb8
52 changes: 25 additions & 27 deletions Lib/test/test_pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,24 @@ def test_spawn_uncommon_exit_code(self):

class PtySpawnTestBase(unittest.TestCase):
"""A base class for the following integration test setup: A child
process is spawned with pty.spawn(). The child runs a fresh python
interpreter; its python code is passed via command line argument as
string. A background process is forked, reusing the current
instance of the python interpreter. These processes are connected
over STDIN/STDOUT pipes. The tests run fork(), select(), execlp(),
and other calls on your system.

Starting from the parent (the main thread of this test suite), three
processes are forked for this setup. We call the spawn()-ed child
the 'slave' because it is connected to the slave side of the pty.
The background process is connected to the master side of the pty.
Internal details require a spawn_runner. The actual tests are
executed between slave and background.
process is spawned with pty.spawn() and a background process is
forked from the test suite. The two processes are connected over
STDIN/STDOUT pipes to communicate. The tests run fork(), select(),
execlp(), and other calls on your system.

Starting from the parent (the main thread of this test suite), the
following processes are forked for this setup:
* The 'slave'. We call the pty.spawn()-ed child the 'slave' because
it is connected to the slave side of the pty. It executes python
code passed as a string. This makes the test suite very
portable. The main test code runs here.
* The 'background' process, which interacts with the slave and
drives the tests. It is connected to the master side of the pty.
Being forked from the parent, it reuses the parent's instance of
the python interpreter.
* The 'spawn_runner', an internal helper to capture the
input/output of the slave.
The actual tests are executed between slave and background.

Sequence diagram of the overall test setup:

Expand Down Expand Up @@ -370,10 +375,6 @@ class PtySpawnTestBase(unittest.TestCase):
background .
|< . . . . . . . . . . . . . . . . . . . . . . . . . . . .



The code for the spawned slave is python code in a string. This
makes the test suite very portable.
"""
# We introduce this generic base class for the test setup to
# encapsulate multiple different types of tests in individual
Expand All @@ -395,12 +396,12 @@ def _pty_spawn(stdin, stdout, args, pre_spawn_hook=''):
# We cannot use the test.support.captured_output() functions
# because the pty module writes to filedescriptors directly.
# We cannot use test.support.script_helper because we need to
# interact with the spawned child.
# interact with the spawned slave.
# We cannot monkey-patch pty.STDIN_FILENO to point to a pipe
# because the fallback path of pty.fork() relies on them.
# Invoking this functions creates two children: the spawn_runner
# as isolated child to execute pty.spawn and capture stdout and
# its grandchild (running args) created by pty.spawn.
# its grandchild (the slave, running args) created by pty.spawn.
spawn_runner = pre_spawn_hook + textwrap.dedent("""
import pty, sys;
ret = pty.spawn(sys.argv[1:]);
Expand Down Expand Up @@ -456,11 +457,8 @@ def _spawn_master_and_slave(self, master_fun, slave_src, close_stdin=False,
sys.stdout.flush()
sys.stderr.flush()
# Without this flush, we interfere with the debug output from
# the child that will be spawned and execute master_fun. Don't
# confuse it with the child spawned by spawn(). It will work
# fine without the flush, unless you enable debug and have your
# STDOUT piped! The forked child will print to the same fd as
# we (the parent) print our debug information to.
# the background process (running master_fun). Parent and
# background process print debug information to the same fd.

io_fds = (write_to_stdin_fd, read_from_stdout_fd)
background_pid = self._fork_background_process(master_fun, io_fds)
Expand All @@ -476,10 +474,10 @@ def _spawn_master_and_slave(self, master_fun, slave_src, close_stdin=False,
debug("killing background process ({:d})".format(background_pid))
os.kill(background_pid, 9)
errmsg = ["Spawned slave returned but failed.",
"The failed child code was:",
"--- BEGIN child code ---",
"The failed slave code was:",
"--- BEGIN slave code ---",
slave_src,
"--- END child code ---"]
"--- END slave code ---"]
rd, _, _ = select.select([read_from_stdout_fd], [], [], 0)
if rd:
errmsg.append("Dumping what the slave wrote last:")
Expand Down