summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-26 12:36:55 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-26 12:36:55 (GMT)
commite254e53c833d39e1e479a16d7976a7726c0c1981 (patch)
tree665b7fcd7a0acb9a38b51bd34fdf9dbe252cc8ff /Lib
parent51e44ea66aefb4229e506263acf40d35596d279c (diff)
downloadcpython-e254e53c833d39e1e479a16d7976a7726c0c1981.zip
cpython-e254e53c833d39e1e479a16d7976a7726c0c1981.tar.gz
cpython-e254e53c833d39e1e479a16d7976a7726c0c1981.tar.bz2
Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
on closed socket. repr(socket.socket) already works fine.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 8b37b21..28bf8f5 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -38,6 +38,11 @@ try:
except ImportError:
thread = None
threading = None
+try:
+ import _socket
+except ImportError:
+ _socket = None
+
def _have_socket_can():
"""Check whether CAN sockets are supported on this host."""
@@ -658,6 +663,19 @@ class GeneralModuleTests(unittest.TestCase):
self.assertIn('[closed]', repr(s))
self.assertNotIn('laddr', repr(s))
+ @unittest.skipUnless(_socket is not None, 'need _socket module')
+ def test_csocket_repr(self):
+ s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
+ try:
+ expected = ('<socket object, fd=%s, family=%s, type=%s, proto=%s>'
+ % (s.fileno(), s.family, s.type, s.proto))
+ self.assertEqual(repr(s), expected)
+ finally:
+ s.close()
+ expected = ('<socket object, fd=-1, family=%s, type=%s, proto=%s>'
+ % (s.family, s.type, s.proto))
+ self.assertEqual(repr(s), expected)
+
def test_weakref(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
p = proxy(s)