@@ -86,6 +86,7 @@ class BaseTaskTests:
86
86
87
87
Task = None
88
88
Future = None
89
+ all_tasks = None
89
90
90
91
def new_task (self , loop , coro , name = 'TestTask' , context = None ):
91
92
return self .__class__ .Task (coro , loop = loop , name = name , context = context )
@@ -2267,7 +2268,7 @@ async def kill_me(loop):
2267
2268
coro = kill_me (self .loop )
2268
2269
task = asyncio .ensure_future (coro , loop = self .loop )
2269
2270
2270
- self .assertEqual (asyncio .all_tasks (loop = self .loop ), {task })
2271
+ self .assertEqual (self .all_tasks (loop = self .loop ), {task })
2271
2272
2272
2273
asyncio .set_event_loop (None )
2273
2274
@@ -2282,7 +2283,7 @@ async def kill_me(loop):
2282
2283
# no more reference to kill_me() task: the task is destroyed by the GC
2283
2284
support .gc_collect ()
2284
2285
2285
- self .assertEqual (asyncio .all_tasks (loop = self .loop ), set ())
2286
+ self .assertEqual (self .all_tasks (loop = self .loop ), set ())
2286
2287
2287
2288
mock_handler .assert_called_with (self .loop , {
2288
2289
'message' : 'Task was destroyed but it is pending!' ,
@@ -2431,7 +2432,7 @@ async def coro():
2431
2432
message = m_log .error .call_args [0 ][0 ]
2432
2433
self .assertIn ('Task was destroyed but it is pending' , message )
2433
2434
2434
- self .assertEqual (asyncio .all_tasks (self .loop ), set ())
2435
+ self .assertEqual (self .all_tasks (self .loop ), set ())
2435
2436
2436
2437
def test_create_task_with_noncoroutine (self ):
2437
2438
with self .assertRaisesRegex (TypeError ,
@@ -2731,6 +2732,7 @@ async def func():
2731
2732
# Add patched Task & Future back to the test case
2732
2733
cls .Task = Task
2733
2734
cls .Future = Future
2735
+ cls .all_tasks = tasks .all_tasks
2734
2736
2735
2737
# Add an extra unit-test
2736
2738
cls .test_subclasses_ctask_cfuture = test_subclasses_ctask_cfuture
@@ -2804,6 +2806,7 @@ class CTask_CFuture_Tests(BaseTaskTests, SetMethodsTest,
2804
2806
2805
2807
Task = getattr (tasks , '_CTask' , None )
2806
2808
Future = getattr (futures , '_CFuture' , None )
2809
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2807
2810
2808
2811
@support .refcount_test
2809
2812
def test_refleaks_in_task___init__ (self ):
@@ -2835,6 +2838,7 @@ class CTask_CFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
2835
2838
2836
2839
Task = getattr (tasks , '_CTask' , None )
2837
2840
Future = getattr (futures , '_CFuture' , None )
2841
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2838
2842
2839
2843
2840
2844
@unittest .skipUnless (hasattr (tasks , '_CTask' ),
@@ -2844,6 +2848,7 @@ class CTaskSubclass_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
2844
2848
2845
2849
Task = getattr (tasks , '_CTask' , None )
2846
2850
Future = futures ._PyFuture
2851
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2847
2852
2848
2853
2849
2854
@unittest .skipUnless (hasattr (futures , '_CFuture' ),
@@ -2853,6 +2858,7 @@ class PyTask_CFutureSubclass_Tests(BaseTaskTests, test_utils.TestCase):
2853
2858
2854
2859
Future = getattr (futures , '_CFuture' , None )
2855
2860
Task = tasks ._PyTask
2861
+ all_tasks = tasks ._py_all_tasks
2856
2862
2857
2863
2858
2864
@unittest .skipUnless (hasattr (tasks , '_CTask' ),
@@ -2861,6 +2867,7 @@ class CTask_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
2861
2867
2862
2868
Task = getattr (tasks , '_CTask' , None )
2863
2869
Future = futures ._PyFuture
2870
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2864
2871
2865
2872
2866
2873
@unittest .skipUnless (hasattr (futures , '_CFuture' ),
@@ -2869,13 +2876,15 @@ class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):
2869
2876
2870
2877
Task = tasks ._PyTask
2871
2878
Future = getattr (futures , '_CFuture' , None )
2879
+ all_tasks = staticmethod (tasks ._py_all_tasks )
2872
2880
2873
2881
2874
2882
class PyTask_PyFuture_Tests (BaseTaskTests , SetMethodsTest ,
2875
2883
test_utils .TestCase ):
2876
2884
2877
2885
Task = tasks ._PyTask
2878
2886
Future = futures ._PyFuture
2887
+ all_tasks = staticmethod (tasks ._py_all_tasks )
2879
2888
2880
2889
2881
2890
@add_subclass_tests
@@ -2915,6 +2924,7 @@ class BaseTaskIntrospectionTests:
2915
2924
_unregister_task = None
2916
2925
_enter_task = None
2917
2926
_leave_task = None
2927
+ all_tasks = None
2918
2928
2919
2929
def test__register_task_1 (self ):
2920
2930
class TaskLike :
@@ -2928,9 +2938,9 @@ def done(self):
2928
2938
task = TaskLike ()
2929
2939
loop = mock .Mock ()
2930
2940
2931
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2941
+ self .assertEqual (self .all_tasks (loop ), set ())
2932
2942
self ._register_task (task )
2933
- self .assertEqual (asyncio .all_tasks (loop ), {task })
2943
+ self .assertEqual (self .all_tasks (loop ), {task })
2934
2944
self ._unregister_task (task )
2935
2945
2936
2946
def test__register_task_2 (self ):
@@ -2944,9 +2954,9 @@ def done(self):
2944
2954
task = TaskLike ()
2945
2955
loop = mock .Mock ()
2946
2956
2947
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2957
+ self .assertEqual (self .all_tasks (loop ), set ())
2948
2958
self ._register_task (task )
2949
- self .assertEqual (asyncio .all_tasks (loop ), {task })
2959
+ self .assertEqual (self .all_tasks (loop ), {task })
2950
2960
self ._unregister_task (task )
2951
2961
2952
2962
def test__register_task_3 (self ):
@@ -2960,9 +2970,9 @@ def done(self):
2960
2970
task = TaskLike ()
2961
2971
loop = mock .Mock ()
2962
2972
2963
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2973
+ self .assertEqual (self .all_tasks (loop ), set ())
2964
2974
self ._register_task (task )
2965
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2975
+ self .assertEqual (self .all_tasks (loop ), set ())
2966
2976
self ._unregister_task (task )
2967
2977
2968
2978
def test__enter_task (self ):
@@ -3013,20 +3023,21 @@ def test__unregister_task(self):
3013
3023
task .get_loop = lambda : loop
3014
3024
self ._register_task (task )
3015
3025
self ._unregister_task (task )
3016
- self .assertEqual (asyncio .all_tasks (loop ), set ())
3026
+ self .assertEqual (self .all_tasks (loop ), set ())
3017
3027
3018
3028
def test__unregister_task_not_registered (self ):
3019
3029
task = mock .Mock ()
3020
3030
loop = mock .Mock ()
3021
3031
self ._unregister_task (task )
3022
- self .assertEqual (asyncio .all_tasks (loop ), set ())
3032
+ self .assertEqual (self .all_tasks (loop ), set ())
3023
3033
3024
3034
3025
3035
class PyIntrospectionTests (test_utils .TestCase , BaseTaskIntrospectionTests ):
3026
3036
_register_task = staticmethod (tasks ._py_register_task )
3027
3037
_unregister_task = staticmethod (tasks ._py_unregister_task )
3028
3038
_enter_task = staticmethod (tasks ._py_enter_task )
3029
3039
_leave_task = staticmethod (tasks ._py_leave_task )
3040
+ all_tasks = staticmethod (tasks ._py_all_tasks )
3030
3041
3031
3042
3032
3043
@unittest .skipUnless (hasattr (tasks , '_c_register_task' ),
@@ -3037,6 +3048,7 @@ class CIntrospectionTests(test_utils.TestCase, BaseTaskIntrospectionTests):
3037
3048
_unregister_task = staticmethod (tasks ._c_unregister_task )
3038
3049
_enter_task = staticmethod (tasks ._c_enter_task )
3039
3050
_leave_task = staticmethod (tasks ._c_leave_task )
3051
+ all_tasks = staticmethod (tasks ._c_all_tasks )
3040
3052
else :
3041
3053
_register_task = _unregister_task = _enter_task = _leave_task = None
3042
3054
0 commit comments