[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) asyncio: Add an unit test to check that setting the

victor.stinner python-checkins at python.org
Mon Jun 23 00:21:59 CEST 2014


http://hg.python.org/cpython/rev/3e87fb8df9c3
changeset:   91328:3e87fb8df9c3
parent:      91326:57cd4ad9ea16
parent:      91327:94cb5ff71106
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jun 23 00:21:09 2014 +0200
summary:
  (Merge 3.4) asyncio: Add an unit test to check that setting the
PYTHONASYNCIODEBUG env var enables debug mode of the event loop.

files:
  Lib/test/test_asyncio/test_base_events.py |  24 +++++++++++
  Lib/test/test_asyncio/test_tasks.py       |   4 -
  2 files changed, 24 insertions(+), 4 deletions(-)


diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -7,6 +7,7 @@
 import time
 import unittest
 from unittest import mock
+from test.script_helper import assert_python_ok
 from test.support import IPV6_ENABLED
 
 import asyncio
@@ -489,6 +490,29 @@
             self.assertIs(type(_context['context']['exception']),
                           ZeroDivisionError)
 
+    def test_env_var_debug(self):
+        code = '\n'.join((
+            'import asyncio',
+            'loop = asyncio.get_event_loop()',
+            'print(loop.get_debug())'))
+
+        # Test with -E to not fail if the unit test was run with
+        # PYTHONASYNCIODEBUG set to a non-empty string
+        sts, stdout, stderr = assert_python_ok('-E', '-c', code)
+        self.assertEqual(stdout.rstrip(), b'False')
+
+        sts, stdout, stderr = assert_python_ok('-c', code,
+                                               PYTHONASYNCIODEBUG='')
+        self.assertEqual(stdout.rstrip(), b'False')
+
+        sts, stdout, stderr = assert_python_ok('-c', code,
+                                               PYTHONASYNCIODEBUG='1')
+        self.assertEqual(stdout.rstrip(), b'True')
+
+        sts, stdout, stderr = assert_python_ok('-E', '-c', code,
+                                               PYTHONASYNCIODEBUG='1')
+        self.assertEqual(stdout.rstrip(), b'False')
+
 
 class MyProto(asyncio.Protocol):
     done = None
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1577,11 +1577,7 @@
         self.assertEqual(fut.result(), [3, 1, exc, exc2])
 
     def test_env_var_debug(self):
-        path = os.path.dirname(asyncio.__file__)
-        path = os.path.normpath(os.path.join(path, '..'))
         code = '\n'.join((
-            'import sys',
-            'sys.path.insert(0, %r)' % path,
             'import asyncio.tasks',
             'print(asyncio.tasks._DEBUG)'))
 

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


More information about the Python-checkins mailing list