Skip to content

Commit 08afe29

Browse files
authored
gh-149879: Fix test_termios and test_ioctl on Cygwin (#150412)
Skip tests failing on Cygwin.
1 parent c714b56 commit 08afe29

2 files changed

Lines changed: 31 additions & 15 deletions

File tree

Lib/test/test_ioctl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def setUp(self):
139139
self.addCleanup(os.close, self.master_fd)
140140

141141
@unittest.skipUnless(hasattr(termios, 'TCFLSH'), 'requires termios.TCFLSH')
142+
@unittest.skipIf(sys.platform == 'cygwin', 'test failed on Cygwin')
142143
def test_ioctl_clear_input_or_output(self):
143144
wfd = self.slave_fd
144145
rfd = self.master_fd

Lib/test/test_termios.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import errno
23
import os
34
import sys
@@ -11,6 +12,19 @@
1112
termios = import_module('termios')
1213

1314

15+
# Skip the test on ENOTTY error
16+
@contextlib.contextmanager
17+
def skip_enotty_error(testcase, func, platforms):
18+
try:
19+
yield
20+
except termios.error as exc:
21+
if (exc.args[0] == errno.ENOTTY
22+
and sys.platform.startswith(platforms)):
23+
testcase.skipTest(f'termios.{func}() is not supported '
24+
f'with pseudo-terminals (?) on {sys.platform}')
25+
raise
26+
27+
1428
@unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()")
1529
class TestFunctions(unittest.TestCase):
1630

@@ -90,7 +104,8 @@ def test_tcsetattr_errors(self):
90104
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW, attrs2)
91105
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW, object())
92106
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW)
93-
self.assertRaisesTermiosError(errno.EINVAL, termios.tcsetattr, self.fd, -1, attrs)
107+
if sys.platform != 'cygwin':
108+
self.assertRaisesTermiosError(errno.EINVAL, termios.tcsetattr, self.fd, -1, attrs)
94109
self.assertRaises(OverflowError, termios.tcsetattr, self.fd, 2**1000, attrs)
95110
self.assertRaises(TypeError, termios.tcsetattr, self.fd, object(), attrs)
96111
self.assertRaisesTermiosError(errno.ENOTTY, termios.tcsetattr, self.bad_fd, termios.TCSANOW, attrs)
@@ -101,14 +116,10 @@ def test_tcsetattr_errors(self):
101116

102117
@support.skip_android_selinux('tcsendbreak')
103118
def test_tcsendbreak(self):
104-
try:
119+
with skip_enotty_error(self, 'tcsendbreak',
120+
('freebsd', 'netbsd', 'cygwin')):
105121
termios.tcsendbreak(self.fd, 1)
106-
except termios.error as exc:
107-
if exc.args[0] == errno.ENOTTY and sys.platform.startswith(('freebsd', "netbsd")):
108-
self.skipTest('termios.tcsendbreak() is not supported '
109-
'with pseudo-terminals (?) on this platform')
110-
raise
111-
termios.tcsendbreak(self.stream, 1)
122+
termios.tcsendbreak(self.stream, 1)
112123

113124
@support.skip_android_selinux('tcsendbreak')
114125
def test_tcsendbreak_errors(self):
@@ -123,8 +134,9 @@ def test_tcsendbreak_errors(self):
123134

124135
@support.skip_android_selinux('tcdrain')
125136
def test_tcdrain(self):
126-
termios.tcdrain(self.fd)
127-
termios.tcdrain(self.stream)
137+
with skip_enotty_error(self, 'tcdrain', ('cygwin',)):
138+
termios.tcdrain(self.fd)
139+
termios.tcdrain(self.stream)
128140

129141
@support.skip_android_selinux('tcdrain')
130142
def test_tcdrain_errors(self):
@@ -149,6 +161,7 @@ def test_tcflush_errors(self):
149161
self.assertRaises(TypeError, termios.tcflush, object(), termios.TCIFLUSH)
150162
self.assertRaises(TypeError, termios.tcflush, self.fd)
151163

164+
@unittest.skipIf(sys.platform == 'cygwin', 'test fails on Cygwin')
152165
def test_tcflush_clear_input_or_output(self):
153166
wfd = self.fd
154167
rfd = self.master_fd
@@ -176,14 +189,16 @@ def test_tcflush_clear_input_or_output(self):
176189

177190
@support.skip_android_selinux('tcflow')
178191
def test_tcflow(self):
179-
termios.tcflow(self.fd, termios.TCOOFF)
180-
termios.tcflow(self.fd, termios.TCOON)
181-
termios.tcflow(self.fd, termios.TCIOFF)
182-
termios.tcflow(self.fd, termios.TCION)
192+
with skip_enotty_error(self, 'tcflow', ('cygwin',)):
193+
termios.tcflow(self.fd, termios.TCOOFF)
194+
termios.tcflow(self.fd, termios.TCOON)
195+
termios.tcflow(self.fd, termios.TCIOFF)
196+
termios.tcflow(self.fd, termios.TCION)
183197

184198
@support.skip_android_selinux('tcflow')
185199
def test_tcflow_errors(self):
186-
self.assertRaisesTermiosError(errno.EINVAL, termios.tcflow, self.fd, -1)
200+
if sys.platform != 'cygwin':
201+
self.assertRaisesTermiosError(errno.EINVAL, termios.tcflow, self.fd, -1)
187202
self.assertRaises(OverflowError, termios.tcflow, self.fd, 2**1000)
188203
self.assertRaises(TypeError, termios.tcflow, self.fd, object())
189204
self.assertRaisesTermiosError(errno.ENOTTY, termios.tcflow, self.bad_fd, termios.TCOON)

0 commit comments

Comments
 (0)