diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-10 22:43:05 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-10 22:43:05 (GMT) |
commit | 16e026cc943460b83a08c058ba4e87c5abf36215 (patch) | |
tree | 77a5692e5b8369dbfc2cb99634f8d844020bf582 /Lib | |
parent | cdd98fb4634f6d3fc0815bfe490e1076e8b6ee9e (diff) | |
download | cpython-16e026cc943460b83a08c058ba4e87c5abf36215.zip cpython-16e026cc943460b83a08c058ba4e87c5abf36215.tar.gz cpython-16e026cc943460b83a08c058ba4e87c5abf36215.tar.bz2 |
Temporary commit of fix to issue #5380 (in order to watch buildbot response)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 41 | ||||
-rw-r--r-- | Lib/test/test_posix.py | 24 |
2 files changed, 62 insertions, 3 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 9ffe646..accf0eb 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2394,6 +2394,47 @@ class MiscIOTest(unittest.TestCase): # baseline "io" module. self._check_abc_inheritance(io) + # Issue #5380: reading all available bytes from a pipe or a PTY when + # the other end has been closed. + + def check_pipe_func(self, pipe_func, buffered): + master_fd, slave_fd = pipe_func() + # Simulate a subprocess writing some data to the + # slave end of the pipe, and then exiting. + data = b'TEST DATA' + try: + os.write(slave_fd, data) + finally: + os.close(slave_fd) + with self.open(master_fd, "rb", buffering=-1 if buffered else 0) as f: + # Request more data than available + gotdata = f.read(len(data) + 1) + self.assertEqual(gotdata, data) + # Trying to read again returns an empty string + self.assertEqual(b'', f.read()) + self.assertEqual(b'', f.read(1)) + + def test_pipe_read_buffered(self): + if not hasattr(os, 'pipe'): + self.skipTest("os.pipe not available") + self.check_pipe_func(os.pipe, True) + + def test_pipe_read_raw(self): + if not hasattr(os, 'pipe'): + self.skipTest("os.pipe not available") + self.check_pipe_func(os.pipe, False) + + def test_openpty_read_buffered(self): + if not hasattr(os, 'openpty'): + self.skipTest("os.openpty not available") + self.check_pipe_func(os.openpty, True) + + def test_openpty_read_raw(self): + if not hasattr(os, 'openpty'): + self.skipTest("os.openpty not available") + self.check_pipe_func(os.openpty, False) + + class CMiscIOTest(MiscIOTest): io = io diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index afeb616..3caf824 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -280,11 +280,29 @@ class PosixTester(unittest.TestCase): if hasattr(posix, 'strerror'): self.assertTrue(posix.strerror(0)) + def check_pipe_func(self, pipe_func): + master_fd, slave_fd = pipe_func() + try: + # Simulate a subprocess writing some data to the + # slave end of the pipe, and then exiting. + data = b'TEST DATA' + try: + os.write(slave_fd, data) + finally: + os.close(slave_fd) + # Request more data than available + gotdata = os.read(master_fd, len(data) + 1) + self.assertEqual(gotdata, data) + finally: + os.close(master_fd) + def test_pipe(self): if hasattr(posix, 'pipe'): - reader, writer = posix.pipe() - os.close(reader) - os.close(writer) + self.check_pipe_func(posix.pipe) + + def test_openpty(self): + if hasattr(posix, 'openpty'): + self.check_pipe_func(posix.openpty) def test_tempnam(self): if hasattr(posix, 'tempnam'): |