Skip to content

Commit 999ce63

Browse files
Improve tests.
1 parent 2463ce6 commit 999ce63

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Lib/test/test_socket.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,27 +1225,22 @@ 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]
1231+
neg_values = [-1, -2, -(1<<15)-1, -(1<<31)-1, -(1<<63)-1, -1<<1000]
12341232
l_bad_values = [1<<32, 1<<1000]
1235-
s_bad_values = (
1236-
l_bad_values +
1237-
[1 << 16, _testcapi.INT_MAX, _testcapi.INT_MAX+1]
1238-
)
1233+
s_bad_values = l_bad_values + [1 << 16, (1<<31)-1, 1<<31]
12391234
for k in s_good_values:
12401235
socket.ntohs(k)
12411236
socket.htons(k)
12421237
for k in l_good_values:
12431238
socket.ntohl(k)
12441239
socket.htonl(k)
1245-
for k in -1, -2, _testcapi.INT_MIN-1, -1<<1000:
1240+
for k in neg_values:
12461241
self.assertRaises(ValueError, socket.ntohs, k)
1247-
self.assertRaises(ValueError, socket.ntohl, k)
12481242
self.assertRaises(ValueError, socket.htons, k)
1243+
self.assertRaises(ValueError, socket.ntohl, k)
12491244
self.assertRaises(ValueError, socket.htonl, k)
12501245
for k in s_bad_values:
12511246
self.assertRaises(OverflowError, socket.ntohs, k)

0 commit comments

Comments
 (0)