mirror of
https://github.com/python/cpython.git
synced 2025-08-17 07:11:51 +00:00
[3.9] bpo-45011: Fix test_asyncio without C module _asyncio (GH-27968) (GH-27970)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 7dc505b865
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
2cdbd3b8b2
commit
970533e65c
6 changed files with 14 additions and 7 deletions
|
@ -28,6 +28,7 @@ class AsyncioTestSuite(unittest.TestSuite):
|
||||||
ignore("asyncio.runners", like=r".*loop argument.*"),
|
ignore("asyncio.runners", like=r".*loop argument.*"),
|
||||||
ignore("asyncio.subprocess", like=r".*loop argument.*"),
|
ignore("asyncio.subprocess", like=r".*loop argument.*"),
|
||||||
ignore("asyncio.tasks", like=r".*loop argument.*"),
|
ignore("asyncio.tasks", like=r".*loop argument.*"),
|
||||||
|
ignore("test.test_asyncio.test_events", like=r".*loop argument.*"),
|
||||||
ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"),
|
ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"),
|
||||||
ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"),
|
ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,6 @@ class FunctionalTestCaseMixin:
|
||||||
self.loop.set_exception_handler(self.loop_exception_handler)
|
self.loop.set_exception_handler(self.loop_exception_handler)
|
||||||
self.__unhandled_exceptions = []
|
self.__unhandled_exceptions = []
|
||||||
|
|
||||||
# Disable `_get_running_loop`.
|
|
||||||
self._old_get_running_loop = asyncio.events._get_running_loop
|
|
||||||
asyncio.events._get_running_loop = lambda: None
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
self.loop.close()
|
self.loop.close()
|
||||||
|
@ -43,7 +39,6 @@ class FunctionalTestCaseMixin:
|
||||||
self.fail('unexpected calls to loop.call_exception_handler()')
|
self.fail('unexpected calls to loop.call_exception_handler()')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
asyncio.events._get_running_loop = self._old_get_running_loop
|
|
||||||
asyncio.set_event_loop(None)
|
asyncio.set_event_loop(None)
|
||||||
self.loop = None
|
self.loop = None
|
||||||
|
|
||||||
|
|
|
@ -876,6 +876,8 @@ class PyFutureInheritanceTests(BaseFutureInheritanceTests,
|
||||||
return futures._PyFuture
|
return futures._PyFuture
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipUnless(hasattr(futures, '_CFuture'),
|
||||||
|
'requires the C _asyncio module')
|
||||||
class CFutureInheritanceTests(BaseFutureInheritanceTests,
|
class CFutureInheritanceTests(BaseFutureInheritanceTests,
|
||||||
test_utils.TestCase):
|
test_utils.TestCase):
|
||||||
def _get_future_cls(self):
|
def _get_future_cls(self):
|
||||||
|
|
|
@ -278,6 +278,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
|
||||||
|
|
||||||
# No garbage is left if SSL is closed uncleanly
|
# No garbage is left if SSL is closed uncleanly
|
||||||
client_context = weakref.ref(client_context)
|
client_context = weakref.ref(client_context)
|
||||||
|
support.gc_collect()
|
||||||
self.assertIsNone(client_context())
|
self.assertIsNone(client_context())
|
||||||
|
|
||||||
def test_create_connection_memory_leak(self):
|
def test_create_connection_memory_leak(self):
|
||||||
|
@ -341,6 +342,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
|
||||||
# No garbage is left for SSL client from loop.create_connection, even
|
# No garbage is left for SSL client from loop.create_connection, even
|
||||||
# if user stores the SSLTransport in corresponding protocol instance
|
# if user stores the SSLTransport in corresponding protocol instance
|
||||||
client_context = weakref.ref(client_context)
|
client_context = weakref.ref(client_context)
|
||||||
|
support.gc_collect()
|
||||||
self.assertIsNone(client_context())
|
self.assertIsNone(client_context())
|
||||||
|
|
||||||
def test_start_tls_client_buf_proto_1(self):
|
def test_start_tls_client_buf_proto_1(self):
|
||||||
|
@ -640,6 +642,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
|
||||||
# The 10s handshake timeout should be cancelled to free related
|
# The 10s handshake timeout should be cancelled to free related
|
||||||
# objects without really waiting for 10s
|
# objects without really waiting for 10s
|
||||||
client_sslctx = weakref.ref(client_sslctx)
|
client_sslctx = weakref.ref(client_sslctx)
|
||||||
|
support.gc_collect()
|
||||||
self.assertIsNone(client_sslctx())
|
self.assertIsNone(client_sslctx())
|
||||||
|
|
||||||
def test_create_connection_ssl_slow_handshake(self):
|
def test_create_connection_ssl_slow_handshake(self):
|
||||||
|
|
|
@ -3196,15 +3196,18 @@ class GenericTaskTests(test_utils.TestCase):
|
||||||
def test_future_subclass(self):
|
def test_future_subclass(self):
|
||||||
self.assertTrue(issubclass(asyncio.Task, asyncio.Future))
|
self.assertTrue(issubclass(asyncio.Task, asyncio.Future))
|
||||||
|
|
||||||
|
@support.cpython_only
|
||||||
def test_asyncio_module_compiled(self):
|
def test_asyncio_module_compiled(self):
|
||||||
# Because of circular imports it's easy to make _asyncio
|
# Because of circular imports it's easy to make _asyncio
|
||||||
# module non-importable. This is a simple test that will
|
# module non-importable. This is a simple test that will
|
||||||
# fail on systems where C modules were successfully compiled
|
# fail on systems where C modules were successfully compiled
|
||||||
# (hence the test for _functools), but _asyncio somehow didn't.
|
# (hence the test for _functools etc), but _asyncio somehow didn't.
|
||||||
try:
|
try:
|
||||||
import _functools
|
import _functools
|
||||||
|
import _json
|
||||||
|
import _pickle
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
self.skipTest('C modules are not available')
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import _asyncio
|
import _asyncio
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Made tests relying on the :mod:`_asyncio` C extension module optional to
|
||||||
|
allow running on alternative Python implementations. Patch by Serhiy
|
||||||
|
Storchaka.
|
Loading…
Add table
Add a link
Reference in a new issue