summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2013-11-14 18:06:18 (GMT)
committerGuido van Rossum <guido@dropbox.com>2013-11-14 18:06:18 (GMT)
commitf38f7f3c7b8b018428a427c33ada455ec09683ca (patch)
tree5786801fb800300b50cf6624448437343992d634 /Lib
parent49d047935720c04d674baed60dba8e832e0243f7 (diff)
downloadcpython-f38f7f3c7b8b018428a427c33ada455ec09683ca.zip
cpython-f38f7f3c7b8b018428a427c33ada455ec09683ca.tar.gz
cpython-f38f7f3c7b8b018428a427c33ada455ec09683ca.tar.bz2
asyncio: Avoid ResourceWarning. Fix issue 19580 by Vajrasky Kok.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 3c4d52e..5178d54 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -458,16 +458,26 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
self.loop.sock_connect.return_value = ()
self.loop._make_ssl_transport = unittest.mock.Mock()
+ class _SelectorTransportMock:
+ _sock = None
+
+ def close(self):
+ self._sock.close()
+
def mock_make_ssl_transport(sock, protocol, sslcontext, waiter,
**kwds):
waiter.set_result(None)
+ transport = _SelectorTransportMock()
+ transport._sock = sock
+ return transport
self.loop._make_ssl_transport.side_effect = mock_make_ssl_transport
ANY = unittest.mock.ANY
# First try the default server_hostname.
self.loop._make_ssl_transport.reset_mock()
coro = self.loop.create_connection(MyProto, 'python.org', 80, ssl=True)
- self.loop.run_until_complete(coro)
+ transport, _ = self.loop.run_until_complete(coro)
+ transport.close()
self.loop._make_ssl_transport.assert_called_with(
ANY, ANY, ANY, ANY,
server_side=False,
@@ -476,7 +486,8 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
self.loop._make_ssl_transport.reset_mock()
coro = self.loop.create_connection(MyProto, 'python.org', 80, ssl=True,
server_hostname='perl.com')
- self.loop.run_until_complete(coro)
+ transport, _ = self.loop.run_until_complete(coro)
+ transport.close()
self.loop._make_ssl_transport.assert_called_with(
ANY, ANY, ANY, ANY,
server_side=False,
@@ -485,7 +496,8 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
self.loop._make_ssl_transport.reset_mock()
coro = self.loop.create_connection(MyProto, 'python.org', 80, ssl=True,
server_hostname='')
- self.loop.run_until_complete(coro)
+ transport, _ = self.loop.run_until_complete(coro)
+ transport.close()
self.loop._make_ssl_transport.assert_called_with(ANY, ANY, ANY, ANY,
server_side=False,
server_hostname='')
@@ -505,8 +517,10 @@ class BaseEventLoopWithSelectorTests(unittest.TestCase):
self.assertRaises(ValueError, self.loop.run_until_complete, coro)
coro = self.loop.create_connection(MyProto, None, 80, ssl=True)
self.assertRaises(ValueError, self.loop.run_until_complete, coro)
+ sock = socket.socket()
coro = self.loop.create_connection(MyProto, None, None,
- ssl=True, sock=socket.socket())
+ ssl=True, sock=sock)
+ self.addCleanup(sock.close)
self.assertRaises(ValueError, self.loop.run_until_complete, coro)
def test_create_server_empty_host(self):