@@ -1169,7 +1169,7 @@ def testInterfaceNameIndex(self):
1169
1169
@support .skip_android_selinux ('if_indextoname' )
1170
1170
def testInvalidInterfaceIndexToName (self ):
1171
1171
self .assertRaises (OSError , socket .if_indextoname , 0 )
1172
- self .assertRaises (OverflowError , socket .if_indextoname , - 1 )
1172
+ self .assertRaises (ValueError , socket .if_indextoname , - 1 )
1173
1173
self .assertRaises (OverflowError , socket .if_indextoname , 2 ** 1000 )
1174
1174
self .assertRaises (TypeError , socket .if_indextoname , '_DEADBEEF' )
1175
1175
if hasattr (socket , 'if_nameindex' ):
@@ -1225,24 +1225,23 @@ def testNtoH(self):
1225
1225
self .assertEqual (swapped & mask , mask )
1226
1226
self .assertRaises (OverflowError , func , 1 << 34 )
1227
1227
1228
- @support .cpython_only
1229
- @unittest .skipIf (_testcapi is None , "requires _testcapi" )
1230
1228
def testNtoHErrors (self ):
1231
- import _testcapi
1232
1229
s_good_values = [0 , 1 , 2 , 0xffff ]
1233
1230
l_good_values = s_good_values + [0xffffffff ]
1234
- l_bad_values = [- 1 , - 2 , 1 << 32 , 1 << 1000 ]
1235
- s_bad_values = (
1236
- l_bad_values +
1237
- [_testcapi .INT_MIN - 1 , _testcapi .INT_MAX + 1 ] +
1238
- [1 << 16 , _testcapi .INT_MAX ]
1239
- )
1231
+ neg_values = [- 1 , - 2 , - (1 << 15 )- 1 , - (1 << 31 )- 1 , - (1 << 63 )- 1 , - 1 << 1000 ]
1232
+ l_bad_values = [1 << 32 , 1 << 1000 ]
1233
+ s_bad_values = l_bad_values + [1 << 16 , (1 << 31 )- 1 , 1 << 31 ]
1240
1234
for k in s_good_values :
1241
1235
socket .ntohs (k )
1242
1236
socket .htons (k )
1243
1237
for k in l_good_values :
1244
1238
socket .ntohl (k )
1245
1239
socket .htonl (k )
1240
+ for k in neg_values :
1241
+ self .assertRaises (ValueError , socket .ntohs , k )
1242
+ self .assertRaises (ValueError , socket .htons , k )
1243
+ self .assertRaises (ValueError , socket .ntohl , k )
1244
+ self .assertRaises (ValueError , socket .htonl , k )
1246
1245
for k in s_bad_values :
1247
1246
self .assertRaises (OverflowError , socket .ntohs , k )
1248
1247
self .assertRaises (OverflowError , socket .htons , k )
0 commit comments