Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Lib/test/test_pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import struct
import tty
import fcntl
import platform
import warnings

TEST_STRING_1 = b"I wish to buy a fish license.\n"
Expand Down Expand Up @@ -82,12 +81,6 @@ def expectedFailureIfStdinIsTTY(fun):
pass
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):
s = struct.pack("HHHH", 0, 0, 0, 0)
return fcntl.ioctl(fd, _TIOCGWINSZ, s)
Expand Down Expand Up @@ -314,7 +307,6 @@ def test_fork(self):

os.close(master_fd)

@expectedFailureOnBSD
def test_master_read(self):
debug("Calling pty.openpty()")
master_fd, slave_fd = pty.openpty()
Expand All @@ -324,10 +316,13 @@ def test_master_read(self):
os.close(slave_fd)

debug("Reading from master_fd")
with self.assertRaises(OSError):
os.read(master_fd, 1)
try:
data = os.read(master_fd, 1)
except OSError: # Linux
data = b""

os.close(master_fd)
self.assertEqual(data, b"")

class SmallPtyTests(unittest.TestCase):
"""These tests don't spawn children or hang."""
Expand Down
Original file line number Diff line number Diff line change
@@ -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.