8
8
9
9
support .requires_working_socket (module = True )
10
10
11
- from asyncio import run , iscoroutinefunction
11
+ from asyncio import run
12
12
from unittest import IsolatedAsyncioTestCase
13
13
from unittest .mock import (ANY , call , AsyncMock , patch , MagicMock , Mock ,
14
14
create_autospec , sentinel , _CallList , seal )
@@ -60,7 +60,7 @@ class AsyncPatchDecoratorTest(unittest.TestCase):
60
60
def test_is_coroutine_function_patch (self ):
61
61
@patch .object (AsyncClass , 'async_method' )
62
62
def test_async (mock_method ):
63
- self .assertTrue (iscoroutinefunction (mock_method ))
63
+ self .assertTrue (inspect . iscoroutinefunction (mock_method ))
64
64
test_async ()
65
65
66
66
def test_is_async_patch (self ):
@@ -121,7 +121,7 @@ class AsyncPatchCMTest(unittest.TestCase):
121
121
def test_is_async_function_cm (self ):
122
122
def test_async ():
123
123
with patch .object (AsyncClass , 'async_method' ) as mock_method :
124
- self .assertTrue (iscoroutinefunction (mock_method ))
124
+ self .assertTrue (inspect . iscoroutinefunction (mock_method ))
125
125
126
126
test_async ()
127
127
@@ -155,7 +155,7 @@ def test_patch_dict_async_def(self):
155
155
async def test_async ():
156
156
self .assertEqual (foo ['a' ], 'b' )
157
157
158
- self .assertTrue (iscoroutinefunction (test_async ))
158
+ self .assertTrue (inspect . iscoroutinefunction (test_async ))
159
159
run (test_async ())
160
160
161
161
def test_patch_dict_async_def_context (self ):
@@ -170,12 +170,11 @@ async def test_async():
170
170
class AsyncMockTest (unittest .TestCase ):
171
171
def test_iscoroutinefunction_default (self ):
172
172
mock = AsyncMock ()
173
- self .assertTrue (iscoroutinefunction (mock ))
173
+ self .assertTrue (inspect . iscoroutinefunction (mock ))
174
174
175
175
def test_iscoroutinefunction_function (self ):
176
176
async def foo (): pass
177
177
mock = AsyncMock (foo )
178
- self .assertTrue (iscoroutinefunction (mock ))
179
178
self .assertTrue (inspect .iscoroutinefunction (mock ))
180
179
181
180
def test_isawaitable (self ):
@@ -188,7 +187,6 @@ def test_isawaitable(self):
188
187
def test_iscoroutinefunction_normal_function (self ):
189
188
def foo (): pass
190
189
mock = AsyncMock (foo )
191
- self .assertTrue (iscoroutinefunction (mock ))
192
190
self .assertTrue (inspect .iscoroutinefunction (mock ))
193
191
194
192
def test_future_isfuture (self ):
@@ -231,7 +229,6 @@ async def main():
231
229
232
230
run (main ())
233
231
234
- self .assertTrue (iscoroutinefunction (spec ))
235
232
self .assertTrue (inspect .iscoroutinefunction (spec ))
236
233
self .assertTrue (asyncio .iscoroutine (awaitable ))
237
234
self .assertTrue (inspect .iscoroutine (awaitable ))
@@ -273,7 +270,6 @@ async def test_async():
273
270
awaitable = mock_method (1 , 2 , c = 3 )
274
271
self .assertIsInstance (mock_method .mock , AsyncMock )
275
272
276
- self .assertTrue (iscoroutinefunction (mock_method ))
277
273
self .assertTrue (inspect .iscoroutinefunction (mock_method ))
278
274
self .assertTrue (asyncio .iscoroutine (awaitable ))
279
275
self .assertTrue (inspect .iscoroutine (awaitable ))
@@ -430,13 +426,13 @@ def test_async(async_method):
430
426
431
427
def test_is_async_AsyncMock (self ):
432
428
mock = AsyncMock (spec_set = AsyncClass .async_method )
433
- self .assertTrue (iscoroutinefunction (mock ))
429
+ self .assertTrue (inspect . iscoroutinefunction (mock ))
434
430
self .assertIsInstance (mock , AsyncMock )
435
431
436
432
def test_is_child_AsyncMock (self ):
437
433
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 ))
440
436
self .assertIsInstance (mock .async_method , AsyncMock )
441
437
self .assertIsInstance (mock .normal_method , MagicMock )
442
438
self .assertIsInstance (mock , MagicMock )
@@ -606,8 +602,8 @@ def test_magic_methods_are_async_functions(self):
606
602
self .assertIsInstance (m_mock .__aenter__ , AsyncMock )
607
603
self .assertIsInstance (m_mock .__aexit__ , AsyncMock )
608
604
# 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__ ))
611
607
612
608
class AsyncContextManagerTest (unittest .TestCase ):
613
609
@@ -746,11 +742,11 @@ def inner_test(mock_type):
746
742
mock_instance = mock_type (instance )
747
743
# Check that the mock and the real thing bahave the same
748
744
# __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__ ))
751
747
# __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__ ))
754
750
755
751
for mock_type in [AsyncMock , MagicMock ]:
756
752
with self .subTest (f"test aiter and anext corourtine with { mock_type } " ):
@@ -806,7 +802,7 @@ def test_assert_called_but_not_awaited(self):
806
802
mock = AsyncMock (AsyncClass )
807
803
with assertNeverAwaited (self ):
808
804
mock .async_method ()
809
- self .assertTrue (iscoroutinefunction (mock .async_method ))
805
+ self .assertTrue (inspect . iscoroutinefunction (mock .async_method ))
810
806
mock .async_method .assert_called ()
811
807
mock .async_method .assert_called_once ()
812
808
mock .async_method .assert_called_once_with ()
0 commit comments