summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorKirill Podoprigora <kirill.bast9@mail.ru>2024-08-17 08:03:51 (GMT)
committerGitHub <noreply@github.com>2024-08-17 08:03:51 (GMT)
commite6d5ff55d0816d7f5eb45e49c810e936b09d2be7 (patch)
tree36a09e8c42d2909570cd623dc29bd09c40c2441f /Lib/test
parent35d8ac7cd7ed6cd3d84af721dce970da59bd5f68 (diff)
downloadcpython-e6d5ff55d0816d7f5eb45e49c810e936b09d2be7.zip
cpython-e6d5ff55d0816d7f5eb45e49c810e936b09d2be7.tar.gz
cpython-e6d5ff55d0816d7f5eb45e49c810e936b09d2be7.tar.bz2
gh-123087: ``Lib/test/test_unittest/testmock/testasync.py``: Replace usage of the deprecated ``asyncio.iscoroutinefunction`` with the ``inspect.iscoroutinefunction`` (#123088)
asyncio.iscoroutinefunction -> inspect.iscoroutinefunction
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_unittest/testmock/testasync.py34
1 files changed, 15 insertions, 19 deletions
diff --git a/Lib/test/test_unittest/testmock/testasync.py b/Lib/test/test_unittest/testmock/testasync.py
index f57b83f..73f0429 100644
--- a/Lib/test/test_unittest/testmock/testasync.py
+++ b/Lib/test/test_unittest/testmock/testasync.py
@@ -8,7 +8,7 @@ from test import support
support.requires_working_socket(module=True)
-from asyncio import run, iscoroutinefunction
+from asyncio import run
from unittest import IsolatedAsyncioTestCase
from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock, Mock,
create_autospec, sentinel, _CallList, seal)
@@ -60,7 +60,7 @@ class AsyncPatchDecoratorTest(unittest.TestCase):
def test_is_coroutine_function_patch(self):
@patch.object(AsyncClass, 'async_method')
def test_async(mock_method):
- self.assertTrue(iscoroutinefunction(mock_method))
+ self.assertTrue(inspect.iscoroutinefunction(mock_method))
test_async()
def test_is_async_patch(self):
@@ -121,7 +121,7 @@ class AsyncPatchCMTest(unittest.TestCase):
def test_is_async_function_cm(self):
def test_async():
with patch.object(AsyncClass, 'async_method') as mock_method:
- self.assertTrue(iscoroutinefunction(mock_method))
+ self.assertTrue(inspect.iscoroutinefunction(mock_method))
test_async()
@@ -155,7 +155,7 @@ class AsyncPatchCMTest(unittest.TestCase):
async def test_async():
self.assertEqual(foo['a'], 'b')
- self.assertTrue(iscoroutinefunction(test_async))
+ self.assertTrue(inspect.iscoroutinefunction(test_async))
run(test_async())
def test_patch_dict_async_def_context(self):
@@ -170,12 +170,11 @@ class AsyncPatchCMTest(unittest.TestCase):
class AsyncMockTest(unittest.TestCase):
def test_iscoroutinefunction_default(self):
mock = AsyncMock()
- self.assertTrue(iscoroutinefunction(mock))
+ self.assertTrue(inspect.iscoroutinefunction(mock))
def test_iscoroutinefunction_function(self):
async def foo(): pass
mock = AsyncMock(foo)
- self.assertTrue(iscoroutinefunction(mock))
self.assertTrue(inspect.iscoroutinefunction(mock))
def test_isawaitable(self):
@@ -188,7 +187,6 @@ class AsyncMockTest(unittest.TestCase):
def test_iscoroutinefunction_normal_function(self):
def foo(): pass
mock = AsyncMock(foo)
- self.assertTrue(iscoroutinefunction(mock))
self.assertTrue(inspect.iscoroutinefunction(mock))
def test_future_isfuture(self):
@@ -231,7 +229,6 @@ class AsyncAutospecTest(unittest.TestCase):
run(main())
- self.assertTrue(iscoroutinefunction(spec))
self.assertTrue(inspect.iscoroutinefunction(spec))
self.assertTrue(asyncio.iscoroutine(awaitable))
self.assertTrue(inspect.iscoroutine(awaitable))
@@ -273,7 +270,6 @@ class AsyncAutospecTest(unittest.TestCase):
awaitable = mock_method(1, 2, c=3)
self.assertIsInstance(mock_method.mock, AsyncMock)
- self.assertTrue(iscoroutinefunction(mock_method))
self.assertTrue(inspect.iscoroutinefunction(mock_method))
self.assertTrue(asyncio.iscoroutine(awaitable))
self.assertTrue(inspect.iscoroutine(awaitable))
@@ -430,13 +426,13 @@ class AsyncSpecSetTest(unittest.TestCase):
def test_is_async_AsyncMock(self):
mock = AsyncMock(spec_set=AsyncClass.async_method)
- self.assertTrue(iscoroutinefunction(mock))
+ self.assertTrue(inspect.iscoroutinefunction(mock))
self.assertIsInstance(mock, AsyncMock)
def test_is_child_AsyncMock(self):
mock = MagicMock(spec_set=AsyncClass)
- self.assertTrue(iscoroutinefunction(mock.async_method))
- self.assertFalse(iscoroutinefunction(mock.normal_method))
+ self.assertTrue(inspect.iscoroutinefunction(mock.async_method))
+ self.assertFalse(inspect.iscoroutinefunction(mock.normal_method))
self.assertIsInstance(mock.async_method, AsyncMock)
self.assertIsInstance(mock.normal_method, MagicMock)
self.assertIsInstance(mock, MagicMock)
@@ -606,8 +602,8 @@ class AsyncMagicMethods(unittest.TestCase):
self.assertIsInstance(m_mock.__aenter__, AsyncMock)
self.assertIsInstance(m_mock.__aexit__, AsyncMock)
# AsyncMocks are also coroutine functions
- self.assertTrue(iscoroutinefunction(m_mock.__aenter__))
- self.assertTrue(iscoroutinefunction(m_mock.__aexit__))
+ self.assertTrue(inspect.iscoroutinefunction(m_mock.__aenter__))
+ self.assertTrue(inspect.iscoroutinefunction(m_mock.__aexit__))
class AsyncContextManagerTest(unittest.TestCase):
@@ -746,11 +742,11 @@ class AsyncIteratorTest(unittest.TestCase):
mock_instance = mock_type(instance)
# Check that the mock and the real thing bahave the same
# __aiter__ is not actually async, so not a coroutinefunction
- self.assertFalse(iscoroutinefunction(instance.__aiter__))
- self.assertFalse(iscoroutinefunction(mock_instance.__aiter__))
+ self.assertFalse(inspect.iscoroutinefunction(instance.__aiter__))
+ self.assertFalse(inspect.iscoroutinefunction(mock_instance.__aiter__))
# __anext__ is async
- self.assertTrue(iscoroutinefunction(instance.__anext__))
- self.assertTrue(iscoroutinefunction(mock_instance.__anext__))
+ self.assertTrue(inspect.iscoroutinefunction(instance.__anext__))
+ self.assertTrue(inspect.iscoroutinefunction(mock_instance.__anext__))
for mock_type in [AsyncMock, MagicMock]:
with self.subTest(f"test aiter and anext corourtine with {mock_type}"):
@@ -806,7 +802,7 @@ class AsyncMockAssert(unittest.TestCase):
mock = AsyncMock(AsyncClass)
with assertNeverAwaited(self):
mock.async_method()
- self.assertTrue(iscoroutinefunction(mock.async_method))
+ self.assertTrue(inspect.iscoroutinefunction(mock.async_method))
mock.async_method.assert_called()
mock.async_method.assert_called_once()
mock.async_method.assert_called_once_with()