summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2002-07-31 15:57:39 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2002-07-31 15:57:39 (GMT)
commitcbd5b89571ee4d619bff2a264cc8a946cc98845f (patch)
tree254a51d42d5d5347ef0e37ab848aff95fee5547d
parentcce7e34aebeed31ac893836f59b69227e2e55a63 (diff)
downloadcpython-cbd5b89571ee4d619bff2a264cc8a946cc98845f.zip
cpython-cbd5b89571ee4d619bff2a264cc8a946cc98845f.tar.gz
cpython-cbd5b89571ee4d619bff2a264cc8a946cc98845f.tar.bz2
Repair testNtoH for large long arguments.
If the long is large enough, the return value will be a negative int. In this case, calling the function a second time won't return the original value passed in.
-rw-r--r--Lib/test/test_socket.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 44b42ff..301cd70 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -248,15 +248,14 @@ class GeneralModuleTests(unittest.TestCase):
pass
def testNtoH(self):
- def twice(f):
- def g(x):
- return f(f(x))
- return g
- for i in (0, 1, 0xffff0000, 2L, (2**32L) - 1):
- self.assertEqual(i, twice(socket.htonl)(i))
- self.assertEqual(i, twice(socket.ntohl)(i))
- self.assertRaises(OverflowError, socket.htonl, 2L**34)
- self.assertRaises(OverflowError, socket.ntohl, 2L**34)
+ for func in socket.htonl, socket.ntohl:
+ for i in (0, 1, 0xffff0000, 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 testGetServByName(self):
"""Testing getservbyname()."""