Skip to content
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
1 change: 1 addition & 0 deletions Lib/test/test_ioctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def setUp(self):
self.addCleanup(os.close, self.master_fd)

@unittest.skipUnless(hasattr(termios, 'TCFLSH'), 'requires termios.TCFLSH')
@unittest.skipIf(sys.platform == 'cygwin', 'test failed on Cygwin')
def test_ioctl_clear_input_or_output(self):
wfd = self.slave_fd
rfd = self.master_fd
Expand Down
45 changes: 30 additions & 15 deletions Lib/test/test_termios.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import errno
import os
import sys
Expand All @@ -11,6 +12,19 @@
termios = import_module('termios')


# Skip the test on ENOTTY error
@contextlib.contextmanager
def skip_enotty_error(testcase, func, platforms):
try:
yield
except termios.error as exc:
if (exc.args[0] == errno.ENOTTY
and sys.platform.startswith(platforms)):
testcase.skipTest(f'termios.{func}() is not supported '
f'with pseudo-terminals (?) on {sys.platform}')
raise


@unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()")
class TestFunctions(unittest.TestCase):

Expand Down Expand Up @@ -90,7 +104,8 @@ def test_tcsetattr_errors(self):
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW, attrs2)
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW, object())
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW)
self.assertRaisesTermiosError(errno.EINVAL, termios.tcsetattr, self.fd, -1, attrs)
if sys.platform != 'cygwin':
self.assertRaisesTermiosError(errno.EINVAL, termios.tcsetattr, self.fd, -1, attrs)
self.assertRaises(OverflowError, termios.tcsetattr, self.fd, 2**1000, attrs)
self.assertRaises(TypeError, termios.tcsetattr, self.fd, object(), attrs)
self.assertRaisesTermiosError(errno.ENOTTY, termios.tcsetattr, self.bad_fd, termios.TCSANOW, attrs)
Expand All @@ -101,14 +116,10 @@ def test_tcsetattr_errors(self):

@support.skip_android_selinux('tcsendbreak')
def test_tcsendbreak(self):
try:
with skip_enotty_error(self, 'tcsendbreak',
('freebsd', 'netbsd', 'cygwin')):
termios.tcsendbreak(self.fd, 1)
except termios.error as exc:
if exc.args[0] == errno.ENOTTY and sys.platform.startswith(('freebsd', "netbsd")):
self.skipTest('termios.tcsendbreak() is not supported '
'with pseudo-terminals (?) on this platform')
raise
termios.tcsendbreak(self.stream, 1)
termios.tcsendbreak(self.stream, 1)

@support.skip_android_selinux('tcsendbreak')
def test_tcsendbreak_errors(self):
Expand All @@ -123,8 +134,9 @@ def test_tcsendbreak_errors(self):

@support.skip_android_selinux('tcdrain')
def test_tcdrain(self):
termios.tcdrain(self.fd)
termios.tcdrain(self.stream)
with skip_enotty_error(self, 'tcdrain', ('cygwin',)):
termios.tcdrain(self.fd)
termios.tcdrain(self.stream)

@support.skip_android_selinux('tcdrain')
def test_tcdrain_errors(self):
Expand All @@ -149,6 +161,7 @@ def test_tcflush_errors(self):
self.assertRaises(TypeError, termios.tcflush, object(), termios.TCIFLUSH)
self.assertRaises(TypeError, termios.tcflush, self.fd)

@unittest.skipIf(sys.platform == 'cygwin', 'test fails on Cygwin')
def test_tcflush_clear_input_or_output(self):
wfd = self.fd
rfd = self.master_fd
Expand Down Expand Up @@ -176,14 +189,16 @@ def test_tcflush_clear_input_or_output(self):

@support.skip_android_selinux('tcflow')
def test_tcflow(self):
termios.tcflow(self.fd, termios.TCOOFF)
termios.tcflow(self.fd, termios.TCOON)
termios.tcflow(self.fd, termios.TCIOFF)
termios.tcflow(self.fd, termios.TCION)
with skip_enotty_error(self, 'tcflow', ('cygwin',)):
termios.tcflow(self.fd, termios.TCOOFF)
termios.tcflow(self.fd, termios.TCOON)
termios.tcflow(self.fd, termios.TCIOFF)
termios.tcflow(self.fd, termios.TCION)

@support.skip_android_selinux('tcflow')
def test_tcflow_errors(self):
self.assertRaisesTermiosError(errno.EINVAL, termios.tcflow, self.fd, -1)
if sys.platform != 'cygwin':
self.assertRaisesTermiosError(errno.EINVAL, termios.tcflow, self.fd, -1)
self.assertRaises(OverflowError, termios.tcflow, self.fd, 2**1000)
self.assertRaises(TypeError, termios.tcflow, self.fd, object())
self.assertRaisesTermiosError(errno.ENOTTY, termios.tcflow, self.bad_fd, termios.TCOON)
Expand Down
Loading