[Python-checkins] cpython (3.4): asyncio: Close transports in tests

victor.stinner python-checkins at python.org
Thu Jan 15 14:26:29 CET 2015


https://hg.python.org/cpython/rev/9dfd33f3657f
changeset:   94175:9dfd33f3657f
branch:      3.4
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jan 15 14:24:55 2015 +0100
summary:
  asyncio: Close transports in tests

* 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

files:
  Lib/test/test_asyncio/test_selector_events.py |   2 +
  Lib/test/test_asyncio/test_sslproto.py        |   4 +++
  Lib/test/test_asyncio/test_subprocess.py      |   1 +
  Lib/test/test_asyncio/test_windows_utils.py   |  11 +++++++--
  4 files changed, 15 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -1180,6 +1180,8 @@
         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()
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -33,6 +33,7 @@
         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 @@
         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()
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -286,6 +286,7 @@
         # "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':
diff --git a/Lib/test/test_asyncio/test_windows_utils.py b/Lib/test/test_asyncio/test_windows_utils.py
--- a/Lib/test/test_asyncio/test_windows_utils.py
+++ b/Lib/test/test_asyncio/test_windows_utils.py
@@ -3,6 +3,7 @@
 import socket
 import sys
 import unittest
+import warnings
 from unittest import mock
 
 if sys.platform != 'win32':
@@ -115,8 +116,10 @@
         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 @@
         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__':

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list