mirror of https://github.com/python/cpython
bpo-46358: modernize `test_asyncio` (GH-30562)
This commit is contained in:
parent
8c49d057bf
commit
f779faccd3
|
@ -21,7 +21,6 @@ from test.support import socket_helper
|
||||||
|
|
||||||
|
|
||||||
MOCK_ANY = mock.ANY
|
MOCK_ANY = mock.ANY
|
||||||
PY34 = sys.version_info >= (3, 4)
|
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
|
@ -596,18 +595,10 @@ class BaseEventLoopTests(test_utils.TestCase):
|
||||||
self.loop.run_forever()
|
self.loop.run_forever()
|
||||||
fut = None # Trigger Future.__del__ or futures._TracebackLogger
|
fut = None # Trigger Future.__del__ or futures._TracebackLogger
|
||||||
support.gc_collect()
|
support.gc_collect()
|
||||||
if PY34:
|
# Future.__del__ in logs error with an actual exception context
|
||||||
# Future.__del__ in Python 3.4 logs error with
|
log.error.assert_called_with(
|
||||||
# an actual exception context
|
test_utils.MockPattern('.*exception was never retrieved'),
|
||||||
log.error.assert_called_with(
|
exc_info=(ZeroDivisionError, MOCK_ANY, MOCK_ANY))
|
||||||
test_utils.MockPattern('.*exception was never retrieved'),
|
|
||||||
exc_info=(ZeroDivisionError, MOCK_ANY, MOCK_ANY))
|
|
||||||
else:
|
|
||||||
# futures._TracebackLogger logs only textual traceback
|
|
||||||
log.error.assert_called_with(
|
|
||||||
test_utils.MockPattern(
|
|
||||||
'.*exception was never retrieved.*ZeroDiv'),
|
|
||||||
exc_info=False)
|
|
||||||
|
|
||||||
def test_set_exc_handler_invalid(self):
|
def test_set_exc_handler_invalid(self):
|
||||||
with self.assertRaisesRegex(TypeError, 'A callable object or None'):
|
with self.assertRaisesRegex(TypeError, 'A callable object or None'):
|
||||||
|
|
|
@ -737,14 +737,6 @@ class EventLoopTestsMixin:
|
||||||
|
|
||||||
@unittest.skipIf(ssl is None, 'No ssl module')
|
@unittest.skipIf(ssl is None, 'No ssl module')
|
||||||
def test_ssl_connect_accepted_socket(self):
|
def test_ssl_connect_accepted_socket(self):
|
||||||
if (sys.platform == 'win32' and
|
|
||||||
sys.version_info < (3, 5) and
|
|
||||||
isinstance(self.loop, proactor_events.BaseProactorEventLoop)
|
|
||||||
):
|
|
||||||
raise unittest.SkipTest(
|
|
||||||
'SSL not supported with proactor event loops before Python 3.5'
|
|
||||||
)
|
|
||||||
|
|
||||||
server_context = test_utils.simple_server_sslcontext()
|
server_context = test_utils.simple_server_sslcontext()
|
||||||
client_context = test_utils.simple_client_sslcontext()
|
client_context = test_utils.simple_client_sslcontext()
|
||||||
|
|
||||||
|
@ -2206,17 +2198,15 @@ class HandleTests(test_utils.TestCase):
|
||||||
self.assertRegex(repr(h), regex)
|
self.assertRegex(repr(h), regex)
|
||||||
|
|
||||||
# partial method
|
# partial method
|
||||||
if sys.version_info >= (3, 4):
|
method = HandleTests.test_handle_repr
|
||||||
method = HandleTests.test_handle_repr
|
cb = functools.partialmethod(method)
|
||||||
cb = functools.partialmethod(method)
|
filename, lineno = test_utils.get_function_source(method)
|
||||||
filename, lineno = test_utils.get_function_source(method)
|
h = asyncio.Handle(cb, (), self.loop)
|
||||||
h = asyncio.Handle(cb, (), self.loop)
|
|
||||||
|
|
||||||
cb_regex = r'<function HandleTests.test_handle_repr .*>'
|
cb_regex = r'<function HandleTests.test_handle_repr .*>'
|
||||||
cb_regex = (r'functools.partialmethod\(%s, , \)\(\)' % cb_regex)
|
cb_regex = fr'functools.partialmethod\({cb_regex}, , \)\(\)'
|
||||||
regex = (r'^<Handle %s at %s:%s>$'
|
regex = fr'^<Handle {cb_regex} at {re.escape(filename)}:{lineno}>$'
|
||||||
% (cb_regex, re.escape(filename), lineno))
|
self.assertRegex(repr(h), regex)
|
||||||
self.assertRegex(repr(h), regex)
|
|
||||||
|
|
||||||
def test_handle_repr_debug(self):
|
def test_handle_repr_debug(self):
|
||||||
self.loop.get_debug.return_value = True
|
self.loop.get_debug.return_value = True
|
||||||
|
|
|
@ -571,13 +571,10 @@ class BaseFutureTests:
|
||||||
test_utils.run_briefly(self.loop)
|
test_utils.run_briefly(self.loop)
|
||||||
support.gc_collect()
|
support.gc_collect()
|
||||||
|
|
||||||
if sys.version_info >= (3, 4):
|
regex = f'^{self.cls.__name__} exception was never retrieved\n'
|
||||||
regex = f'^{self.cls.__name__} exception was never retrieved\n'
|
exc_info = (type(exc), exc, exc.__traceback__)
|
||||||
exc_info = (type(exc), exc, exc.__traceback__)
|
m_log.error.assert_called_once_with(mock.ANY, exc_info=exc_info)
|
||||||
m_log.error.assert_called_once_with(mock.ANY, exc_info=exc_info)
|
|
||||||
else:
|
|
||||||
regex = r'^Future/Task exception was never retrieved\n'
|
|
||||||
m_log.error.assert_called_once_with(mock.ANY, exc_info=False)
|
|
||||||
message = m_log.error.call_args[0][0]
|
message = m_log.error.call_args[0][0]
|
||||||
self.assertRegex(message, re.compile(regex, re.DOTALL))
|
self.assertRegex(message, re.compile(regex, re.DOTALL))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue