Skip to content

Commit 4698234

Browse files
Fix tcflush() tests on BSD and OpenIndiana.
1 parent 0ed2f66 commit 4698234

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Lib/test/test_ioctl.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import array
22
import os
33
import struct
4+
import sys
45
import threading
56
import unittest
67
from test.support import get_attribute
@@ -144,15 +145,26 @@ def setUp(self):
144145
self.addCleanup(os.close, self.master_fd)
145146

146147
@unittest.skipUnless(hasattr(termios, 'TCFLSH'), 'requires termios.TCFLSH')
147-
def test_ioctl_clear_input(self):
148+
def test_ioctl_clear_input_or_output(self):
148149
wfd = self.slave_fd
149150
rfd = self.master_fd
151+
inbuf = sys.platform == 'linux'
150152

151153
os.write(wfd, b'abcdef')
152154
self.assertEqual(os.read(rfd, 2), b'ab')
153-
fcntl.ioctl(rfd, termios.TCFLSH, termios.TCOFLUSH) # don't flush input
155+
if inbuf:
156+
# don't flush input
157+
fcntl.ioctl(rfd, termios.TCFLSH, termios.TCOFLUSH)
158+
else:
159+
# don't flush output
160+
fcntl.ioctl(wfd, termios.TCFLSH, termios.TCIFLUSH)
154161
self.assertEqual(os.read(rfd, 2), b'cd')
155-
fcntl.ioctl(rfd, termios.TCFLSH, termios.TCIFLUSH) # flush input
162+
if inbuf:
163+
# flush input
164+
fcntl.ioctl(rfd, termios.TCFLSH, termios.TCIFLUSH)
165+
else:
166+
# flush output
167+
fcntl.ioctl(wfd, termios.TCFLSH, termios.TCOFLUSH)
156168
os.write(wfd, b'ABCDEF')
157169
self.assertEqual(os.read(rfd, 1024), b'ABCDEF')
158170

Lib/test/test_termios.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,26 @@ def test_tcflush_errors(self):
149149
self.assertRaises(TypeError, termios.tcflush, object(), termios.TCIFLUSH)
150150
self.assertRaises(TypeError, termios.tcflush, self.fd)
151151

152-
def test_tcflush_clear_input(self):
152+
def test_tcflush_clear_input_or_output(self):
153153
wfd = self.fd
154154
rfd = self.master_fd
155+
inbuf = sys.platform == 'linux'
155156

156157
os.write(wfd, b'abcdef')
157158
self.assertEqual(os.read(rfd, 2), b'ab')
158-
termios.tcflush(rfd, termios.TCOFLUSH) # don't flush input
159+
if inbuf:
160+
# don't flush input
161+
termios.tcflush(rfd, termios.TCOFLUSH)
162+
else:
163+
# don't flush output
164+
termios.tcflush(wfd, termios.TCIFLUSH)
159165
self.assertEqual(os.read(rfd, 2), b'cd')
160-
termios.tcflush(rfd, termios.TCIFLUSH) # flush input
166+
if inbuf:
167+
# flush input
168+
termios.tcflush(rfd, termios.TCIFLUSH)
169+
else:
170+
# flush output
171+
termios.tcflush(wfd, termios.TCOFLUSH)
161172
os.write(wfd, b'ABCDEF')
162173
self.assertEqual(os.read(rfd, 1024), b'ABCDEF')
163174

0 commit comments

Comments
 (0)