@@ -1169,7 +1169,7 @@ def testInterfaceNameIndex(self):
11691169 @support .skip_android_selinux ('if_indextoname' )
11701170 def testInvalidInterfaceIndexToName (self ):
11711171 self .assertRaises (OSError , socket .if_indextoname , 0 )
1172- self .assertRaises (OverflowError , socket .if_indextoname , - 1 )
1172+ self .assertRaises (ValueError , socket .if_indextoname , - 1 )
11731173 self .assertRaises (OverflowError , socket .if_indextoname , 2 ** 1000 )
11741174 self .assertRaises (TypeError , socket .if_indextoname , '_DEADBEEF' )
11751175 if hasattr (socket , 'if_nameindex' ):
@@ -1225,24 +1225,23 @@ def testNtoH(self):
12251225 self .assertEqual (swapped & mask , mask )
12261226 self .assertRaises (OverflowError , func , 1 << 34 )
12271227
1228- @support .cpython_only
1229- @unittest .skipIf (_testcapi is None , "requires _testcapi" )
12301228 def testNtoHErrors (self ):
1231- import _testcapi
12321229 s_good_values = [0 , 1 , 2 , 0xffff ]
12331230 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 ]
12401234 for k in s_good_values :
12411235 socket .ntohs (k )
12421236 socket .htons (k )
12431237 for k in l_good_values :
12441238 socket .ntohl (k )
12451239 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 )
12461245 for k in s_bad_values :
12471246 self .assertRaises (OverflowError , socket .ntohs , k )
12481247 self .assertRaises (OverflowError , socket .htons , k )
0 commit comments