summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-09-14 00:58:46 (GMT)
committerGuido van Rossum <guido@python.org>2002-09-14 00:58:46 (GMT)
commita2627afe370dc6607be45d5b4cf7f73077507441 (patch)
tree30c84052a69fbf90cb7551347c238eaa4d506334 /Lib
parent92cfaf68c75bd178093e6cedce7a3b5e315f8c9a (diff)
downloadcpython-a2627afe370dc6607be45d5b4cf7f73077507441.zip
cpython-a2627afe370dc6607be45d5b4cf7f73077507441.tar.gz
cpython-a2627afe370dc6607be45d5b4cf7f73077507441.tar.bz2
Maybe this fixes test_socket on 64-bit Linux.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 016dd3c..3dea4e0 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -248,15 +248,19 @@ class GeneralModuleTests(unittest.TestCase):
except socket.error:
pass
- def testNtoH(self):
- for func in socket.htonl, socket.ntohl:
- for i in (0, 1, ~0xffff, 2L):
- self.assertEqual(i, func(func(i)))
-
- biglong = 2**32L - 1
- swapped = func(biglong)
- self.assert_(swapped == biglong or swapped == -1)
- self.assertRaises(OverflowError, func, 2L**34)
+ def testNtoHL(self):
+ # This just checks that htons etc. are their own inverse,
+ # when looking at the lower 16 or 32 bits.
+ sizes = {socket.htonl: 32, socket.ntohl: 32,
+ socket.htons: 16, socket.ntohs: 16}
+ for func, size in sizes.items():
+ mask = (1L<<size) - 1
+ for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210):
+ self.assertEqual(i & mask, func(func(i&mask)) & mask)
+
+ swapped = func(mask)
+ self.assertEqual(swapped & mask, mask)
+ self.assertRaises(OverflowError, func, 1L<<34)
def testGetServByName(self):
# Testing getservbyname()