3
3
import sys
4
4
import tempfile
5
5
import unittest
6
+ from test import support
6
7
from test .support .import_helper import import_module
7
8
8
9
termios = import_module ('termios' )
@@ -18,10 +19,16 @@ def setUp(self):
18
19
tmp = self .enterContext (tempfile .TemporaryFile (mode = 'wb' , buffering = 0 ))
19
20
self .bad_fd = tmp .fileno ()
20
21
21
- def assertRaisesTermiosError (self , errno , callable , * args ):
22
+ def assertRaisesTermiosError (self , err , callable , * args ):
23
+ # Some versions of Android return EACCES when calling termios functions
24
+ # on a regular file.
25
+ errs = [err ]
26
+ if sys .platform == 'android' and err == errno .ENOTTY :
27
+ errs .append (errno .EACCES )
28
+
22
29
with self .assertRaises (termios .error ) as cm :
23
30
callable (* args )
24
- self .assertEqual (cm .exception .args [0 ], errno )
31
+ self .assertIn (cm .exception .args [0 ], errs )
25
32
26
33
def test_tcgetattr (self ):
27
34
attrs = termios .tcgetattr (self .fd )
@@ -90,6 +97,7 @@ def test_tcsetattr_errors(self):
90
97
self .assertRaises (TypeError , termios .tcsetattr , object (), termios .TCSANOW , attrs )
91
98
self .assertRaises (TypeError , termios .tcsetattr , self .fd , termios .TCSANOW )
92
99
100
+ @support .skip_android_selinux ('tcsendbreak' )
93
101
def test_tcsendbreak (self ):
94
102
try :
95
103
termios .tcsendbreak (self .fd , 1 )
@@ -100,6 +108,7 @@ def test_tcsendbreak(self):
100
108
raise
101
109
termios .tcsendbreak (self .stream , 1 )
102
110
111
+ @support .skip_android_selinux ('tcsendbreak' )
103
112
def test_tcsendbreak_errors (self ):
104
113
self .assertRaises (OverflowError , termios .tcsendbreak , self .fd , 2 ** 1000 )
105
114
self .assertRaises (TypeError , termios .tcsendbreak , self .fd , 0.0 )
@@ -110,10 +119,12 @@ def test_tcsendbreak_errors(self):
110
119
self .assertRaises (TypeError , termios .tcsendbreak , object (), 0 )
111
120
self .assertRaises (TypeError , termios .tcsendbreak , self .fd )
112
121
122
+ @support .skip_android_selinux ('tcdrain' )
113
123
def test_tcdrain (self ):
114
124
termios .tcdrain (self .fd )
115
125
termios .tcdrain (self .stream )
116
126
127
+ @support .skip_android_selinux ('tcdrain' )
117
128
def test_tcdrain_errors (self ):
118
129
self .assertRaisesTermiosError (errno .ENOTTY , termios .tcdrain , self .bad_fd )
119
130
self .assertRaises (ValueError , termios .tcdrain , - 1 )
@@ -136,12 +147,14 @@ def test_tcflush_errors(self):
136
147
self .assertRaises (TypeError , termios .tcflush , object (), termios .TCIFLUSH )
137
148
self .assertRaises (TypeError , termios .tcflush , self .fd )
138
149
150
+ @support .skip_android_selinux ('tcflow' )
139
151
def test_tcflow (self ):
140
152
termios .tcflow (self .fd , termios .TCOOFF )
141
153
termios .tcflow (self .fd , termios .TCOON )
142
154
termios .tcflow (self .fd , termios .TCIOFF )
143
155
termios .tcflow (self .fd , termios .TCION )
144
156
157
+ @support .skip_android_selinux ('tcflow' )
145
158
def test_tcflow_errors (self ):
146
159
self .assertRaisesTermiosError (errno .EINVAL , termios .tcflow , self .fd , - 1 )
147
160
self .assertRaises (OverflowError , termios .tcflow , self .fd , 2 ** 1000 )
0 commit comments