diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-27 17:30:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-27 17:30:11 (GMT) |
commit | 3a3e8731a49afcbf9363342e99bd3ef4c72df885 (patch) | |
tree | 4cb5e23c344bae8191fb1f86cfe0c994ded1d184 | |
parent | 27ccb7e1ae31fe2469e37f4d78ba905201a0977e (diff) | |
download | cpython-3a3e8731a49afcbf9363342e99bd3ef4c72df885.zip cpython-3a3e8731a49afcbf9363342e99bd3ef4c72df885.tar.gz cpython-3a3e8731a49afcbf9363342e99bd3ef4c72df885.tar.bz2 |
[3.11] gh-114100: Remove superfluous writing to fd 1 in test_pty (GH-114647) (GH-114656)
(cherry picked from commit 7a470541e2bbc6f3e87a6d813e2ec42cf726de7a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r-- | Lib/test/test_pty.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index f31a68c..51e3a46 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -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 @@ -292,7 +293,26 @@ class PtyTest(unittest.TestCase): 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.""" |