]> granicus.if.org Git - python/commitdiff
asyncio: Add an unit test to check that setting the PYTHONASYNCIODEBUG env var
authorVictor Stinner <victor.stinner@gmail.com>
Sun, 22 Jun 2014 22:19:33 +0000 (00:19 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Sun, 22 Jun 2014 22:19:33 +0000 (00:19 +0200)
enables debug mode of the event loop.

Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_tasks.py

index 352af4887c017f30882d52266ec4ee47fa0702b5..b238f4ea01f62afa9d1fcf4543d81177a7afc774 100644 (file)
@@ -7,6 +7,7 @@ import sys
 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 @@ class BaseEventLoopTests(test_utils.TestCase):
             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
index 3c358a211d65c89e549674a341d8d2240a452046..4b55a8afb0f532be3b7de6f79ca676e17f25f04f 100644 (file)
@@ -1577,11 +1577,7 @@ class GatherTestsBase:
         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)'))