aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2025-04-29 19:27:07 +0300
committerGitHub <noreply@github.com>2025-04-29 19:27:07 +0300
commit4265854d96c907ce7bd5cde164ebb2b7e99b8f3f (patch)
tree2becf29bd980e911a2280d8dd1ff52bb8d8cc267 /Lib/test/test_socket.py
parentc33efa8735dfdb24011f5754f5e9e991c05f0587 (diff)
downloadcpython-4265854d96c907ce7bd5cde164ebb2b7e99b8f3f.tar.gz
cpython-4265854d96c907ce7bd5cde164ebb2b7e99b8f3f.zip
gh-132987: Support __index__() in the socket module (GH-133093)
ntohl(), htonl(), if_indextoname(), getaddrinfo() now use __index__() if available. Also fix the Argument Clinic names for module-level functions (although this does not affect the user).
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index e88611ee314..ace97ce0cbe 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1169,7 +1169,7 @@ class GeneralModuleTests(unittest.TestCase):
@support.skip_android_selinux('if_indextoname')
def testInvalidInterfaceIndexToName(self):
self.assertRaises(OSError, socket.if_indextoname, 0)
- self.assertRaises(OverflowError, socket.if_indextoname, -1)
+ self.assertRaises(ValueError, socket.if_indextoname, -1)
self.assertRaises(OverflowError, socket.if_indextoname, 2**1000)
self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF')
if hasattr(socket, 'if_nameindex'):
@@ -1225,24 +1225,23 @@ class GeneralModuleTests(unittest.TestCase):
self.assertEqual(swapped & mask, mask)
self.assertRaises(OverflowError, func, 1<<34)
- @support.cpython_only
- @unittest.skipIf(_testcapi is None, "requires _testcapi")
def testNtoHErrors(self):
- import _testcapi
s_good_values = [0, 1, 2, 0xffff]
l_good_values = s_good_values + [0xffffffff]
- l_bad_values = [-1, -2, 1<<32, 1<<1000]
- s_bad_values = (
- l_bad_values +
- [_testcapi.INT_MIN-1, _testcapi.INT_MAX+1] +
- [1 << 16, _testcapi.INT_MAX]
- )
+ neg_values = [-1, -2, -(1<<15)-1, -(1<<31)-1, -(1<<63)-1, -1<<1000]
+ l_bad_values = [1<<32, 1<<1000]
+ s_bad_values = l_bad_values + [1 << 16, (1<<31)-1, 1<<31]
for k in s_good_values:
socket.ntohs(k)
socket.htons(k)
for k in l_good_values:
socket.ntohl(k)
socket.htonl(k)
+ for k in neg_values:
+ self.assertRaises(ValueError, socket.ntohs, k)
+ self.assertRaises(ValueError, socket.htons, k)
+ self.assertRaises(ValueError, socket.ntohl, k)
+ self.assertRaises(ValueError, socket.htonl, k)
for k in s_bad_values:
self.assertRaises(OverflowError, socket.ntohs, k)
self.assertRaises(OverflowError, socket.htons, k)