From 4265854d96c907ce7bd5cde164ebb2b7e99b8f3f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 29 Apr 2025 19:27:07 +0300 Subject: 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). --- Lib/test/test_socket.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'Lib/test/test_socket.py') 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) -- cgit v1.2.3