8000 gh-132987: Support __index__() in the socket module by serhiy-storchaka · Pull Request #133093 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132987: Support __index__() in the socket module #133093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve tests.
  • Loading branch information
serhiy-storchaka committed Apr 29, 2025
commit 999ce6362c93b35e5a000a4d7be9c565cddb9c18
13 changes: 4 additions & 9 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,27 +1225,22 @@ def testNtoH(self):
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]
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, _testcapi.INT_MAX, _testcapi.INT_MAX+1]
)
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 -1, -2, _testcapi.INT_MIN-1, -1<<1000:
for k in neg_values:
self.assertRaises(ValueError, socket.ntohs, k)
self.assertRaises(ValueError, socket.ntohl, 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)
Expand Down
Loading
0