bpo-40275: Add asyncioutils in test.support by shihai1991 · Pull Request #19592 · python/cpython · GitHub
Skip to content
Closed
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
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/save_env.py
5 changes: 0 additions & 5 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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 @@ -3255,10 +3254,6 @@ def __gt__(self, other):

SMALLEST = _SMALLEST()

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

# Helpers for testing hashing.
NHASHBITS = sys.hash_info.width # number of bits in hash() result
assert NHASHBITS in (32, 64)
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/support/asyncioutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Utilities to support asyncio in the Python regression tests."""

import asyncio.events

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
3 changes: 2 additions & 1 deletion Lib/test/test_asyncio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from asyncio import tasks
from asyncio.log import logger
from test import support
from test.support.asyncioutils import maybe_get_event_loop_policy


def data_file(filename):
Expand Down Expand Up @@ -515,7 +516,7 @@ def close_loop(loop):
else:
loop._default_executor.shutdown(wait=True)
loop.close()
policy = support.maybe_get_event_loop_policy()
policy = maybe_get_event_loop_policy()
if policy is not None:
try:
watcher = policy.get_child_watcher()
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_builtin.py