Show More
@@ -5,6 +5,7 b' Tests the buffering behavior of stdio st' | |||
|
5 | 5 | from __future__ import absolute_import |
|
6 | 6 | |
|
7 | 7 | import contextlib |
|
8 | import errno | |
|
8 | 9 | import os |
|
9 | 10 | import subprocess |
|
10 | 11 | import sys |
@@ -62,6 +63,23 b' def _ptys():' | |||
|
62 | 63 | yield rwpair |
|
63 | 64 | |
|
64 | 65 | |
|
66 | def _readall(fd, buffer_size): | |
|
67 | buf = [] | |
|
68 | while True: | |
|
69 | try: | |
|
70 | s = os.read(fd, buffer_size) | |
|
71 | except OSError as e: | |
|
72 | if e.errno == errno.EIO: | |
|
73 | # If the child-facing PTY got closed, reading from the | |
|
74 | # parent-facing PTY raises EIO. | |
|
75 | break | |
|
76 | raise | |
|
77 | if not s: | |
|
78 | break | |
|
79 | buf.append(s) | |
|
80 | return b''.join(buf) | |
|
81 | ||
|
82 | ||
|
65 | 83 | class TestStdio(unittest.TestCase): |
|
66 | 84 | def _test(self, stream, rwpair_generator, expected_output, python_args=[]): |
|
67 | 85 | assert stream in ('stdout', 'stderr') |
@@ -76,9 +94,14 b' class TestStdio(unittest.TestCase):' | |||
|
76 | 94 | stdout=child_stream if stream == 'stdout' else None, |
|
77 | 95 | stderr=child_stream if stream == 'stderr' else None, |
|
78 | 96 | ) |
|
79 | retcode = proc.wait() | |
|
97 | try: | |
|
98 | os.close(child_stream) | |
|
99 | self.assertEqual( | |
|
100 | _readall(stream_receiver, 1024), expected_output | |
|
101 | ) | |
|
102 | finally: | |
|
103 | retcode = proc.wait() | |
|
80 | 104 | self.assertEqual(retcode, 0) |
|
81 | self.assertEqual(os.read(stream_receiver, 1024), expected_output) | |
|
82 | 105 | |
|
83 | 106 | def test_stdout_pipes(self): |
|
84 | 107 | self._test('stdout', _pipes, FULLY_BUFFERED) |
General Comments 0
You need to be logged in to leave comments.
Login now