[Python-checkins] cpython (merge 3.4 -> default): Merge with Python 3.4

victor.stinner python-checkins at python.org
Mon Jul 14 22:28:04 CEST 2014


http://hg.python.org/cpython/rev/41c8fc189671
changeset:   91682:41c8fc189671
parent:      91680:dbf991650441
parent:      91681:e461e352d426
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jul 14 22:26:57 2014 +0200
summary:
  Merge with Python 3.4

files:
  Lib/asyncio/test_utils.py                     |  16 ++++++
  Lib/test/test_asyncio/test_events.py          |  23 +++++----
  Lib/test/test_asyncio/test_selector_events.py |  15 +++---
  3 files changed, 37 insertions(+), 17 deletions(-)


diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py
--- a/Lib/asyncio/test_utils.py
+++ b/Lib/asyncio/test_utils.py
@@ -3,6 +3,7 @@
 import collections
 import contextlib
 import io
+import logging
 import os
 import re
 import socket
@@ -28,6 +29,7 @@
 from . import selectors
 from . import tasks
 from .coroutines import coroutine
+from .log import logger
 
 
 if sys.platform == 'win32':  # pragma: no cover
@@ -401,3 +403,17 @@
 
     def tearDown(self):
         events.set_event_loop(None)
+
+
+ at contextlib.contextmanager
+def disable_logger():
+    """Context manager to disable asyncio logger.
+
+    For example, it can be used to ignore warnings in debug mode.
+    """
+    old_level = logger.level
+    try:
+        logger.setLevel(logging.CRITICAL+1)
+        yield
+    finally:
+        logger.setLevel(old_level)
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -819,9 +819,10 @@
         # no CA loaded
         f_c = self.loop.create_connection(MyProto, host, port,
                                           ssl=sslcontext_client)
-        with self.assertRaisesRegex(ssl.SSLError,
-                                    'certificate verify failed '):
-            self.loop.run_until_complete(f_c)
+        with test_utils.disable_logger():
+            with self.assertRaisesRegex(ssl.SSLError,
+                                        'certificate verify failed '):
+                self.loop.run_until_complete(f_c)
 
         # close connection
         self.assertIsNone(proto.transport)
@@ -845,9 +846,10 @@
         f_c = self.loop.create_unix_connection(MyProto, path,
                                                ssl=sslcontext_client,
                                                server_hostname='invalid')
-        with self.assertRaisesRegex(ssl.SSLError,
-                                    'certificate verify failed '):
-            self.loop.run_until_complete(f_c)
+        with test_utils.disable_logger():
+            with self.assertRaisesRegex(ssl.SSLError,
+                                        'certificate verify failed '):
+                self.loop.run_until_complete(f_c)
 
         # close connection
         self.assertIsNone(proto.transport)
@@ -871,10 +873,11 @@
         # incorrect server_hostname
         f_c = self.loop.create_connection(MyProto, host, port,
                                           ssl=sslcontext_client)
-        with self.assertRaisesRegex(
-                ssl.CertificateError,
-                "hostname '127.0.0.1' doesn't match 'localhost'"):
-            self.loop.run_until_complete(f_c)
+        with test_utils.disable_logger():
+            with self.assertRaisesRegex(
+                    ssl.CertificateError,
+                    "hostname '127.0.0.1' doesn't match 'localhost'"):
+                self.loop.run_until_complete(f_c)
 
         # close connection
         proto.transport.close()
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
@@ -1105,13 +1105,13 @@
     def test_on_handshake_exc(self):
         exc = ValueError()
         self.sslsock.do_handshake.side_effect = exc
-        transport = _SelectorSslTransport(
-            self.loop, self.sock, self.protocol, self.sslcontext)
-        transport._waiter = asyncio.Future(loop=self.loop)
-        transport._on_handshake(None)
+        with test_utils.disable_logger():
+            waiter = asyncio.Future(loop=self.loop)
+            transport = _SelectorSslTransport(
+                self.loop, self.sock, self.protocol, self.sslcontext, waiter)
+        self.assertTrue(waiter.done())
+        self.assertIs(exc, waiter.exception())
         self.assertTrue(self.sslsock.close.called)
-        self.assertTrue(transport._waiter.done())
-        self.assertIs(exc, transport._waiter.exception())
 
     def test_on_handshake_base_exc(self):
         transport = _SelectorSslTransport(
@@ -1119,7 +1119,8 @@
         transport._waiter = asyncio.Future(loop=self.loop)
         exc = BaseException()
         self.sslsock.do_handshake.side_effect = exc
-        self.assertRaises(BaseException, transport._on_handshake, None)
+        with test_utils.disable_logger():
+            self.assertRaises(BaseException, transport._on_handshake, None)
         self.assertTrue(self.sslsock.close.called)
         self.assertTrue(transport._waiter.done())
         self.assertIs(exc, transport._waiter.exception())

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


More information about the Python-checkins mailing list