|
1 | 1 | from test.support import verbose, reap_children
|
| 2 | +from test.support.os_helper import TESTFN, unlink |
2 | 3 | from test.support.import_helper import import_module
|
3 | 4 |
|
4 | 5 | # Skip these tests if termios or fcntl are not available
|
@@ -292,7 +293,26 @@ def test_master_read(self):
|
292 | 293 | self.assertEqual(data, b"")
|
293 | 294 |
|
294 | 295 | def test_spawn_doesnt_hang(self):
|
295 |
| - pty.spawn([sys.executable, '-c', 'print("hi there")']) |
| 296 | + self.addCleanup(unlink, TESTFN) |
| 297 | + with open(TESTFN, 'wb') as f: |
| 298 | + STDOUT_FILENO = 1 |
| 299 | + dup_stdout = os.dup(STDOUT_FILENO) |
| 300 | + os.dup2(f.fileno(), STDOUT_FILENO) |
| 301 | + buf = b'' |
| 302 | + def master_read(fd): |
| 303 | + nonlocal buf |
| 304 | + data = os.read(fd, 1024) |
| 305 | + buf += data |
| 306 | + return data |
| 307 | + try: |
| 308 | + pty.spawn([sys.executable, '-c', 'print("hi there")'], |
| 309 | + master_read) |
| 310 | + finally: |
| 311 | + os.dup2(dup_stdout, STDOUT_FILENO) |
| 312 | + os.close(dup_stdout) |
| 313 | + self.assertEqual(buf, b'hi there\r\n') |
| 314 | + with open(TESTFN, 'rb') as f: |
| 315 | + self.assertEqual(f.read(), b'hi there\r\n') |
296 | 316 |
|
297 | 317 | class SmallPtyTests(unittest.TestCase):
|
298 | 318 | """These tests don't spawn children or hang."""
|
|
0 commit comments