bpo-41818: Fix test_master_read() so that it succeeds on all platforms that either raise OSError or return b"" upon reading from master (GH-23536)

Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
This commit is contained in:
Soumendra Ganguly 2020-11-28 15:04:20 -06:00 committed by GitHub
parent aa1b8a168d
commit 74311aeb45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 10 deletions

View File

@ -17,7 +17,6 @@ import unittest
import struct import struct
import tty import tty
import fcntl import fcntl
import platform
import warnings import warnings
TEST_STRING_1 = b"I wish to buy a fish license.\n" TEST_STRING_1 = b"I wish to buy a fish license.\n"
@ -82,12 +81,6 @@ def expectedFailureIfStdinIsTTY(fun):
pass pass
return fun return fun
def expectedFailureOnBSD(fun):
PLATFORM = platform.system()
if PLATFORM.endswith("BSD") or PLATFORM == "Darwin":
return unittest.expectedFailure(fun)
return fun
def _get_term_winsz(fd): def _get_term_winsz(fd):
s = struct.pack("HHHH", 0, 0, 0, 0) s = struct.pack("HHHH", 0, 0, 0, 0)
return fcntl.ioctl(fd, _TIOCGWINSZ, s) return fcntl.ioctl(fd, _TIOCGWINSZ, s)
@ -314,7 +307,6 @@ class PtyTest(unittest.TestCase):
os.close(master_fd) os.close(master_fd)
@expectedFailureOnBSD
def test_master_read(self): def test_master_read(self):
debug("Calling pty.openpty()") debug("Calling pty.openpty()")
master_fd, slave_fd = pty.openpty() master_fd, slave_fd = pty.openpty()
@ -324,10 +316,13 @@ class PtyTest(unittest.TestCase):
os.close(slave_fd) os.close(slave_fd)
debug("Reading from master_fd") debug("Reading from master_fd")
with self.assertRaises(OSError): try:
os.read(master_fd, 1) data = os.read(master_fd, 1)
except OSError: # Linux
data = b""
os.close(master_fd) os.close(master_fd)
self.assertEqual(data, b"")
class SmallPtyTests(unittest.TestCase): class SmallPtyTests(unittest.TestCase):
"""These tests don't spawn children or hang.""" """These tests don't spawn children or hang."""

View File

@ -0,0 +1 @@
Fix test_master_read() so that it succeeds on all platforms that either raise OSError or return b"" upon reading from master.