88
99support .requires_working_socket (module = True )
1010
11- from asyncio import run , iscoroutinefunction
11+ from asyncio import run
1212from unittest import IsolatedAsyncioTestCase
1313from unittest .mock import (ANY , call , AsyncMock , patch , MagicMock , Mock ,
1414 create_autospec , sentinel , _CallList , seal )
@@ -60,7 +60,7 @@ class AsyncPatchDecoratorTest(unittest.TestCase):
6060 def test_is_coroutine_function_patch (self ):
6161 @patch .object (AsyncClass , 'async_method' )
6262 def test_async (mock_method ):
63- self .assertTrue (iscoroutinefunction (mock_method ))
63+ self .assertTrue (inspect . iscoroutinefunction (mock_method ))
6464 test_async ()
6565
6666 def test_is_async_patch (self ):
@@ -121,7 +121,7 @@ class AsyncPatchCMTest(unittest.TestCase):
121121 def test_is_async_function_cm (self ):
122122 def test_async ():
123123 with patch .object (AsyncClass , 'async_method' ) as mock_method :
124- self .assertTrue (iscoroutinefunction (mock_method ))
124+ self .assertTrue (inspect . iscoroutinefunction (mock_method ))
125125
126126 test_async ()
127127
@@ -155,7 +155,7 @@ def test_patch_dict_async_def(self):
155155 async def test_async ():
156156 self .assertEqual (foo ['a' ], 'b' )
157157
158- self .assertTrue (iscoroutinefunction (test_async ))
158+ self .assertTrue (inspect . iscoroutinefunction (test_async ))
159159 run (test_async ())
160160
161161 def test_patch_dict_async_def_context (self ):
@@ -170,12 +170,11 @@ async def test_async():
170170class AsyncMockTest (unittest .TestCase ):
171171 def test_iscoroutinefunction_default (self ):
172172 mock = AsyncMock ()
173- self .assertTrue (iscoroutinefunction (mock ))
173+ self .assertTrue (inspect . iscoroutinefunction (mock ))
174174
175175 def test_iscoroutinefunction_function (self ):
176176 async def foo (): pass
177177 mock = AsyncMock (foo )
178- self .assertTrue (iscoroutinefunction (mock ))
179178 self .assertTrue (inspect .iscoroutinefunction (mock ))
180179
181180 def test_isawaitable (self ):
@@ -188,7 +187,6 @@ def test_isawaitable(self):
188187 def test_iscoroutinefunction_normal_function (self ):
189188 def foo (): pass
190189 mock = AsyncMock (foo )
191- self .assertTrue (iscoroutinefunction (mock ))
192190 self .assertTrue (inspect .iscoroutinefunction (mock ))
193191
194192 def test_future_isfuture (self ):
@@ -231,7 +229,6 @@ async def main():
231229
232230 run (main ())
233231
234- self .assertTrue (iscoroutinefunction (spec ))
235232 self .assertTrue (inspect .iscoroutinefunction (spec ))
236233 self .assertTrue (asyncio .iscoroutine (awaitable ))
237234 self .assertTrue (inspect .iscoroutine (awaitable ))
@@ -273,7 +270,6 @@ async def test_async():
273270 awaitable = mock_method (1 , 2 , c = 3 )
274271 self .assertIsInstance (mock_method .mock , AsyncMock )
275272
276- self .assertTrue (iscoroutinefunction (mock_method ))
277273 self .assertTrue (inspect .iscoroutinefunction (mock_method ))
278274 self .assertTrue (asyncio .iscoroutine (awaitable ))
279275 self .assertTrue (inspect .iscoroutine (awaitable ))
@@ -430,13 +426,13 @@ def test_async(async_method):
430426
431427 def test_is_async_AsyncMock (self ):
432428 mock = AsyncMock (spec_set = AsyncClass .async_method )
433- self .assertTrue (iscoroutinefunction (mock ))
429+ self .assertTrue (inspect . iscoroutinefunction (mock ))
434430 self .assertIsInstance (mock , AsyncMock )
435431
436432 def test_is_child_AsyncMock (self ):
437433 mock = MagicMock (spec_set = AsyncClass )
438- self .assertTrue (iscoroutinefunction (mock .async_method ))
439- self .assertFalse (iscoroutinefunction (mock .normal_method ))
434+ self .assertTrue (inspect . iscoroutinefunction (mock .async_method ))
435+ self .assertFalse (inspect . iscoroutinefunction (mock .normal_method ))
440436 self .assertIsInstance (mock .async_method , AsyncMock )
441437 self .assertIsInstance (mock .normal_method , MagicMock )
442438 self .assertIsInstance (mock , MagicMock )
@@ -606,8 +602,8 @@ def test_magic_methods_are_async_functions(self):
606602 self .assertIsInstance (m_mock .__aenter__ , AsyncMock )
607603 self .assertIsInstance (m_mock .__aexit__ , AsyncMock )
608604 # AsyncMocks are also coroutine functions
609- self .assertTrue (iscoroutinefunction (m_mock .__aenter__ ))
610- self .assertTrue (iscoroutinefunction (m_mock .__aexit__ ))
605+ self .assertTrue (inspect . iscoroutinefunction (m_mock .__aenter__ ))
606+ self .assertTrue (inspect . iscoroutinefunction (m_mock .__aexit__ ))
611607
612608class AsyncContextManagerTest (unittest .TestCase ):
613609
@@ -746,11 +742,11 @@ def inner_test(mock_type):
746742 mock_instance = mock_type (instance )
747743 # Check that the mock and the real thing bahave the same
748744 # __aiter__ is not actually async, so not a coroutinefunction
749- self .assertFalse (iscoroutinefunction (instance .__aiter__ ))
750- self .assertFalse (iscoroutinefunction (mock_instance .__aiter__ ))
745+ self .assertFalse (inspect . iscoroutinefunction (instance .__aiter__ ))
746+ self .assertFalse (inspect . iscoroutinefunction (mock_instance .__aiter__ ))
751747 # __anext__ is async
752- self .assertTrue (iscoroutinefunction (instance .__anext__ ))
753- self .assertTrue (iscoroutinefunction (mock_instance .__anext__ ))
748+ self .assertTrue (inspect . iscoroutinefunction (instance .__anext__ ))
749+ self .assertTrue (inspect . iscoroutinefunction (mock_instance .__anext__ ))
754750
755751 for mock_type in [AsyncMock , MagicMock ]:
756752 with self .subTest (f"test aiter and anext corourtine with { mock_type } " ):
@@ -806,7 +802,7 @@ def test_assert_called_but_not_awaited(self):
806802 mock = AsyncMock (AsyncClass )
807803 with assertNeverAwaited (self ):
808804 mock .async_method ()
809- self .assertTrue (iscoroutinefunction (mock .async_method ))
805+ self .assertTrue (inspect . iscoroutinefunction (mock .async_method ))
810806 mock .async_method .assert_called ()
811807 mock .async_method .assert_called_once ()
812808 mock .async_method .assert_called_once_with ()
0 commit comments