Skip to content

Commit

Permalink
pythongh-114100: Remove superfluous writing to fd 1 in test_pty (pyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored and aisk committed Feb 11, 2024
1 parent 548e5cf commit 55401d8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Lib/test/test_pty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from test.support import verbose, reap_children
from test.support.os_helper import TESTFN, unlink
from test.support.import_helper import import_module

# Skip these tests if termios or fcntl are not available
Expand Down Expand Up @@ -292,7 +293,26 @@ def test_master_read(self):
self.assertEqual(data, b"")

def test_spawn_doesnt_hang(self):
pty.spawn([sys.executable, '-c', 'print("hi there")'])
self.addCleanup(unlink, TESTFN)
with open(TESTFN, 'wb') as f:
STDOUT_FILENO = 1
dup_stdout = os.dup(STDOUT_FILENO)
os.dup2(f.fileno(), STDOUT_FILENO)
buf = b''
def master_read(fd):
nonlocal buf
data = os.read(fd, 1024)
buf += data
return data
try:
pty.spawn([sys.executable, '-c', 'print("hi there")'],
master_read)
finally:
os.dup2(dup_stdout, STDOUT_FILENO)
os.close(dup_stdout)
self.assertEqual(buf, b'hi there\r\n')
with open(TESTFN, 'rb') as f:
self.assertEqual(f.read(), b'hi there\r\n')

class SmallPtyTests(unittest.TestCase):
"""These tests don't spawn children or hang."""
Expand Down

0 comments on commit 55401d8

Please sign in to comment.