Skip to content

Commit 9f62b82

Browse files
committed
Make a high-level test, remove outdated comments, add more cleanups
1 parent 9613c98 commit 9f62b82

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

Lib/pty.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
# Author: Steen Lumholt -- with additions by Guido.
88

99
from select import select
10-
from os import close, waitpid
1110
import os
1211
import sys
13-
from tty import setraw, tcgetattr, tcsetattr
1412
import tty
1513

14+
# names imported directly for test mocking purposes
15+
from os import close, waitpid
16+
from tty import setraw, tcgetattr, tcsetattr
17+
1618
__all__ = ["openpty", "fork", "spawn"]
1719

1820
STDIN_FILENO = 0

Lib/test/test_pty.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ def handle_sig(self, sig, frame):
124124

125125
@staticmethod
126126
def handle_sighup(signum, frame):
127-
# bpo-38547: if the process is the session leader, os.close(master_fd)
128-
# of "master_fd, slave_name = pty.master_open()" raises SIGHUP
129-
# signal: just ignore the signal.
130-
#
131-
# NOTE: the above comment is from an older version of the test;
132-
# master_open() is not being used anymore.
133127
pass
134128

135129
@expectedFailureIfStdinIsTTY
@@ -191,13 +185,6 @@ def test_openpty(self):
191185
self.assertEqual(_get_term_winsz(slave_fd), new_stdin_winsz,
192186
"openpty() failed to set slave window size")
193187

194-
# Solaris requires reading the fd before anything is returned.
195-
# My guess is that since we open and close the slave fd
196-
# in master_open(), we need to read the EOF.
197-
#
198-
# NOTE: the above comment is from an older version of the test;
199-
# master_open() is not being used anymore.
200-
201188
# Ensure the fd is non-blocking in case there's nothing to read.
202189
blocking = os.get_blocking(master_fd)
203190
try:
@@ -325,12 +312,17 @@ def test_master_read(self):
325312

326313
self.assertEqual(data, b"")
327314

315+
def test_spawn_doesnt_hang(self):
316+
pty.spawn([sys.executable, '-c', 'print("hi there")'])
317+
328318
class SmallPtyTests(unittest.TestCase):
329319
"""These tests don't spawn children or hang."""
330320

331321
def setUp(self):
332322
self.orig_stdin_fileno = pty.STDIN_FILENO
333323
self.orig_stdout_fileno = pty.STDOUT_FILENO
324+
self.orig_pty_close = pty.close
325+
self.orig_pty__copy = pty._copy
334326
self.orig_pty_fork = pty.fork
335327
self.orig_pty_select = pty.select
336328
self.orig_pty_setraw = pty.setraw
@@ -346,6 +338,8 @@ def setUp(self):
346338
def tearDown(self):
347339
pty.STDIN_FILENO = self.orig_stdin_fileno
348340
pty.STDOUT_FILENO = self.orig_stdout_fileno
341+
pty.close = self.orig_pty_close
342+
pty._copy = self.orig_pty__copy
349343
pty.fork = self.orig_pty_fork
350344
pty.select = self.orig_pty_select
351345
pty.setraw = self.orig_pty_setraw

0 commit comments

Comments
 (0)