asyncio, Tulip issue #136: Add get/set_debug() methods to BaseEventLoopTests.

Add also a PYTHONASYNCIODEBUG environment variable to debug coroutines since
Python startup, to be able to debug coroutines defined directly in the asyncio
module.
This commit is contained in:
Victor Stinner 2014-02-19 23:15:02 +01:00
parent f4558e8b54
commit 7ef60cd8c2
8 changed files with 83 additions and 5 deletions

View file

@ -1,7 +1,9 @@
"""Tests for tasks.py."""
import gc
import os.path
import unittest
from test.script_helper import assert_python_ok
import asyncio
from asyncio import test_utils
@ -1461,6 +1463,32 @@ class GatherTestsBase:
cb.assert_called_once_with(fut)
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)'))
# 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 FutureGatherTests(GatherTestsBase, unittest.TestCase):