Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/libregrtest/save_env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import builtins
import locale
import logging
Expand Down Expand Up @@ -65,8 +66,14 @@ def __init__(self, testname, verbose=0, quiet=False, *, pgo=False):
'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
'files', 'locale', 'warnings.showwarning',
'shutil_archive_formats', 'shutil_unpack_formats',
'asyncio.events._event_loop_policy',
)

def get_asyncio_events__event_loop_policy(self):
return support.maybe_get_event_loop_policy()
def restore_asyncio_events__event_loop_policy(self, policy):
asyncio.set_event_loop_policy(policy)

def get_sys_argv(self):
return id(sys.argv), sys.argv, sys.argv[:]
def restore_sys_argv(self, saved_argv):
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
if __name__ != 'test.support':
raise ImportError('support must be imported from the test package')

import asyncio.events
import collections.abc
import contextlib
import errno
Expand Down Expand Up @@ -2878,3 +2879,8 @@ def __fspath__(self):
raise self.path
else:
return self.path


def maybe_get_event_loop_policy():
"""Return the global event loop policy if one is set, else return None."""
return asyncio.events._event_loop_policy
1 change: 1 addition & 0 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def setUp(self):
def tearDown(self):
self.loop.close()
self.loop = None
asyncio.set_event_loop_policy(None)

async def to_list(self, gen):
res = []
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
PY34 = sys.version_info >= (3, 4)


def tearDownModule():
asyncio.set_event_loop_policy(None)


def mock_socket_module():
m_socket = mock.MagicMock(spec=socket)
for name in (
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_buffered_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from test.test_asyncio import functional as func_tests


def tearDownModule():
asyncio.set_event_loop_policy(None)


class ReceiveStuffProto(asyncio.BufferedProtocol):
def __init__(self, cb, con_lost_fut):
self.cb = cb
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import unittest


def tearDownModule():
asyncio.set_event_loop_policy(None)


class DecimalContextTest(unittest.TestCase):

def test_asyncio_task_decimal_context(self):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
from test import support


def tearDownModule():
asyncio.set_event_loop_policy(None)


def osx_tiger():
"""Return True if the platform is Mac OS 10.4 or older."""
if sys.platform != 'darwin':
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from test import support


def tearDownModule():
asyncio.set_event_loop_policy(None)


def _fakefunc(f):
return f

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
RGX_REPR = re.compile(STR_RGX_REPR)


def tearDownModule():
asyncio.set_event_loop_policy(None)


class LockTests(test_utils.TestCase):

def setUp(self):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_pep492.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from test.test_asyncio import utils as test_utils


def tearDownModule():
asyncio.set_event_loop_policy(None)


# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
class FakeCoro:
def send(self, value):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from test.test_asyncio import utils as test_utils


def tearDownModule():
asyncio.set_event_loop_policy(None)


def close_transport(transport):
# Don't call transport.close() because the event loop and the IOCP proactor
# are mocked
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from test.test_asyncio import utils as test_utils


def tearDownModule():
asyncio.set_event_loop_policy(None)


class _QueueTestBase(test_utils.TestCase):

def setUp(self):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
MOCK_ANY = mock.ANY


def tearDownModule():
asyncio.set_event_loop_policy(None)


class TestBaseSelectorEventLoop(BaseSelectorEventLoop):

def _make_self_pipe(self):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from test.test_asyncio import functional as func_tests


def tearDownModule():
asyncio.set_event_loop_policy(None)


class BaseStartServer(func_tests.FunctionalTestCaseMixin):

def new_loop(self):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from test.test_asyncio import functional as func_tests


def tearDownModule():
asyncio.set_event_loop_policy(None)


@unittest.skipIf(ssl is None, 'No ssl module')
class SslProtoHandshakeTests(test_utils.TestCase):

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from test.test_asyncio import utils as test_utils


def tearDownModule():
asyncio.set_event_loop_policy(None)


class StreamTests(test_utils.TestCase):

DATA = b'line1\nline2\nline3\n'
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
'data = sys.stdin.buffer.read()',
'sys.stdout.buffer.write(data)'))]


def tearDownModule():
asyncio.set_event_loop_policy(None)


class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
def _start(self, *args, **kwargs):
self._proc = mock.Mock()
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from test.support.script_helper import assert_python_ok


def tearDownModule():
asyncio.set_event_loop_policy(None)


@asyncio.coroutine
def coroutine_function():
pass
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
MOCK_ANY = mock.ANY


def tearDownModule():
asyncio.set_event_loop_policy(None)


def close_pipe_transport(transport):
# Don't call transport.close() because the event loop and the selector
# are mocked
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from test.test_asyncio import utils as test_utils


def tearDownModule():
asyncio.set_event_loop_policy(None)


class UpperProto(asyncio.Protocol):
def __init__(self):
self.buf = []
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_asyncio/test_windows_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
import _overlapped
import _winapi

import asyncio
from asyncio import windows_utils
from test import support


def tearDownModule():
asyncio.set_event_loop_policy(None)


class PipeTests(unittest.TestCase):

def test_pipe_overlapped(self):
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_contextlib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def wrapper(*args, **kwargs):
return loop.run_until_complete(coro)
finally:
loop.close()
asyncio.set_event_loop(None)
asyncio.set_event_loop_policy(None)
return wrapper


Expand Down Expand Up @@ -295,6 +295,7 @@ def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.addCleanup(self.loop.close)
self.addCleanup(asyncio.set_event_loop_policy, None)

@_async_test
async def test_async_callback(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ async def f():
pass
finally:
loop.close()
asyncio.set_event_loop(None)
asyncio.set_event_loop_policy(None)

self.assertEqual(buffer, [1, 2, 'MyException'])

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ def test_pdb_next_command_for_coroutine():
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")

>>> with PdbTestInput(['step',
Expand Down Expand Up @@ -804,6 +805,7 @@ def test_pdb_next_command_for_asyncgen():
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")

>>> with PdbTestInput(['step',
Expand Down Expand Up @@ -915,6 +917,7 @@ def test_pdb_return_command_for_coroutine():
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")

>>> with PdbTestInput(['step',
Expand Down Expand Up @@ -1005,6 +1008,7 @@ def test_pdb_until_command_for_coroutine():
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")

>>> with PdbTestInput(['step',
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ def run_async_test(self, func, jumpFrom, jumpTo, expected, error=None,
with self.assertRaisesRegex(*error):
asyncio.run(func(output))
sys.settrace(None)
asyncio.set_event_loop_policy(None)
self.compare_jump_output(expected, output)

def jump_test(jumpFrom, jumpTo, expected, error=None, event='line'):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Check that a global asyncio event loop policy is not left behind by any
tests.