]> granicus.if.org Git - python/commitdiff
asyncio: Close transports in tests
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 15 Jan 2015 13:24:55 +0000 (14:24 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 15 Jan 2015 13:24:55 +0000 (14:24 +0100)
* Use test_utils.run_briefly() to execute pending calls to really close
  transports
* sslproto: mock also _SSLPipe.shutdown(), it's need to close the transport
* pipe test: the test doesn't close explicitly the PipeHandle, so ignore
  the warning instead
* test_popen: use the context manager ("with p:") to explicitly close pipes

Lib/test/test_asyncio/test_selector_events.py
Lib/test/test_asyncio/test_sslproto.py
Lib/test/test_asyncio/test_subprocess.py
Lib/test/test_asyncio/test_windows_utils.py

index f99d04d44ce8f696821f65361c92baa67cd3e7c9..ad86ada3425a1d2ea24a0a56a8ac60bb1ae81937 100644 (file)
@@ -1180,6 +1180,8 @@ class SelectorSslTransportTests(test_utils.TestCase):
         self.sslsock.do_handshake.side_effect = exc
         with test_utils.disable_logger():
             transport._on_handshake(0)
+        transport.close()
+        test_utils.run_briefly(self.loop)
 
     def test_pause_resume_reading(self):
         tr = self._make_one()
index 053fefe7136400b0b04eb1923dd433e32e1a8e0e..812dedbe1d796be5a116d9ccbde0c640b4c3190a 100644 (file)
@@ -33,6 +33,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
         waiter.cancel()
         transport = mock.Mock()
         sslpipe = mock.Mock()
+        sslpipe.shutdown.return_value = b''
         sslpipe.do_handshake.side_effect = do_handshake
         with mock.patch('asyncio.sslproto._SSLPipe', return_value=sslpipe):
             ssl_proto.connection_made(transport)
@@ -40,6 +41,9 @@ class SslProtoHandshakeTests(test_utils.TestCase):
         with test_utils.disable_logger():
             self.loop.run_until_complete(handshake_fut)
 
+        # Close the transport
+        ssl_proto._app_transport.close()
+
 
 if __name__ == '__main__':
     unittest.main()
index b2f1b953e646f96b9d8d3ec56cd26356ebf66c9f..a4c1f698197cf51574a57bfba06a292d1e42803a 100644 (file)
@@ -286,6 +286,7 @@ class SubprocessMixin:
         # "Exception during subprocess creation, kill the subprocess"
         with test_utils.disable_logger():
             self.loop.run_until_complete(cancel_make_transport())
+            test_utils.run_briefly(self.loop)
 
 
 if sys.platform != 'win32':
index af5c453b087478ade4f5b469d6eb92bb4d7935dd..d48b8bcbb0874fd7fa40701d9ae909d5bb8dff0d 100644 (file)
@@ -3,6 +3,7 @@
 import socket
 import sys
 import unittest
+import warnings
 from unittest import mock
 
 if sys.platform != 'win32':
@@ -115,8 +116,10 @@ class PipeTests(unittest.TestCase):
         self.assertEqual(p.handle, h)
 
         # check garbage collection of p closes handle
-        del p
-        support.gc_collect()
+        with warnings.catch_warnings():
+            warnings.filterwarnings("ignore", "",  ResourceWarning)
+            del p
+            support.gc_collect()
         try:
             _winapi.CloseHandle(h)
         except OSError as e:
@@ -170,7 +173,9 @@ class PopenTests(unittest.TestCase):
         self.assertTrue(msg.upper().rstrip().startswith(out))
         self.assertTrue(b"stderr".startswith(err))
 
-        p.wait()
+        # The context manager calls wait() and closes resources
+        with p:
+            pass
 
 
 if __name__ == '__main__':