@@ -85,6 +85,7 @@ class BaseTaskTests:
85
85
86
86
Task = None
87
87
Future = None
88
+ all_tasks = None
88
89
89
90
def new_task (self , loop , coro , name = 'TestTask' , context = None ):
90
91
return self .__class__ .Task (coro , loop = loop , name = name , context = context )
@@ -2087,7 +2088,7 @@ async def kill_me(loop):
2087
2088
coro = kill_me (self .loop )
2088
2089
task = asyncio .ensure_future (coro , loop = self .loop )
2089
2090
2090
- self .assertEqual (asyncio .all_tasks (loop = self .loop ), {task })
2091
+ self .assertEqual (self .all_tasks (loop = self .loop ), {task })
2091
2092
2092
2093
asyncio .set_event_loop (None )
2093
2094
@@ -2102,7 +2103,7 @@ async def kill_me(loop):
2102
2103
# no more reference to kill_me() task: the task is destroyed by the GC
2103
2104
support .gc_collect ()
2104
2105
2105
- self .assertEqual (asyncio .all_tasks (loop = self .loop ), set ())
2106
+ self .assertEqual (self .all_tasks (loop = self .loop ), set ())
2106
2107
2107
2108
mock_handler .assert_called_with (self .loop , {
2108
2109
'message' : 'Task was destroyed but it is pending!' ,
@@ -2251,7 +2252,7 @@ async def coro():
2251
2252
message = m_log .error .call_args [0 ][0 ]
2252
2253
self .assertIn ('Task was destroyed but it is pending' , message )
2253
2254
2254
- self .assertEqual (asyncio .all_tasks (self .loop ), set ())
2255
+ self .assertEqual (self .all_tasks (self .loop ), set ())
2255
2256
2256
2257
def test_create_task_with_noncoroutine (self ):
2257
2258
with self .assertRaisesRegex (TypeError ,
@@ -2551,6 +2552,7 @@ async def func():
2551
2552
# Add patched Task & Future back to the test case
2552
2553
cls .Task = Task
2553
2554
cls .Future = Future
2555
+ cls .all_tasks = tasks .all_tasks
2554
2556
2555
2557
# Add an extra unit-test
2556
2558
cls .test_subclasses_ctask_cfuture = test_subclasses_ctask_cfuture
@@ -2624,6 +2626,7 @@ class CTask_CFuture_Tests(BaseTaskTests, SetMethodsTest,
2624
2626
2625
2627
Task = getattr (tasks , '_CTask' , None )
2626
2628
Future = getattr (futures , '_CFuture' , None )
2629
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2627
2630
2628
2631
@support .refcount_test
2629
2632
def test_refleaks_in_task___init__ (self ):
@@ -2655,6 +2658,7 @@ class CTask_CFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
2655
2658
2656
2659
Task = getattr (tasks , '_CTask' , None )
2657
2660
Future = getattr (futures , '_CFuture' , None )
2661
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2658
2662
2659
2663
2660
2664
@unittest .skipUnless (hasattr (tasks , '_CTask' ),
@@ -2664,6 +2668,7 @@ class CTaskSubclass_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
2664
2668
2665
2669
Task = getattr (tasks , '_CTask' , None )
2666
2670
Future = futures ._PyFuture
2671
+ all_tasks = getattr (tasks , '_py_all_tasks' , None )
2667
2672
2668
2673
2669
2674
@unittest .skipUnless (hasattr (futures , '_CFuture' ),
@@ -2673,6 +2678,7 @@ class PyTask_CFutureSubclass_Tests(BaseTaskTests, test_utils.TestCase):
2673
2678
2674
2679
Future = getattr (futures , '_CFuture' , None )
2675
2680
Task = tasks ._PyTask
2681
+ all_tasks = getattr (tasks , '_py_all_tasks' , None )
2676
2682
2677
2683
2678
2684
@unittest .skipUnless (hasattr (tasks , '_CTask' ),
@@ -2681,6 +2687,7 @@ class CTask_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
2681
2687
2682
2688
Task = getattr (tasks , '_CTask' , None )
2683
2689
Future = futures ._PyFuture
2690
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2684
2691
2685
2692
2686
2693
@unittest .skipUnless (hasattr (futures , '_CFuture' ),
@@ -2689,13 +2696,15 @@ class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):
2689
2696
2690
2697
Task = tasks ._PyTask
2691
2698
Future = getattr (futures , '_CFuture' , None )
2699
+ all_tasks = getattr (tasks , '_c_all_tasks' , None )
2692
2700
2693
2701
2694
2702
class PyTask_PyFuture_Tests (BaseTaskTests , SetMethodsTest ,
2695
2703
test_utils .TestCase ):
2696
2704
2697
2705
Task = tasks ._PyTask
2698
2706
Future = futures ._PyFuture
2707
+ all_tasks = asyncio .all_tasks
2699
2708
2700
2709
2701
2710
@add_subclass_tests
@@ -2735,6 +2744,7 @@ class BaseTaskIntrospectionTests:
2735
2744
_unregister_task = None
2736
2745
_enter_task = None
2737
2746
_leave_task = None
2747
+ all_tasks = None
2738
2748
2739
2749
def test__register_task_1 (self ):
2740
2750
class TaskLike :
@@ -2748,9 +2758,9 @@ def done(self):
2748
2758
task = TaskLike ()
2749
2759
loop = mock .Mock ()
2750
2760
2751
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2761
+ self .assertEqual (self .all_tasks (loop ), set ())
2752
2762
self ._register_task (task )
2753
- self .assertEqual (asyncio .all_tasks (loop ), {task })
2763
+ self .assertEqual (self .all_tasks (loop ), {task })
2754
2764
self ._unregister_task (task )
2755
2765
2756
2766
def test__register_task_2 (self ):
@@ -2764,9 +2774,9 @@ def done(self):
2764
2774
task = TaskLike ()
2765
2775
loop = mock .Mock ()
2766
2776
2767
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2777
+ self .assertEqual (self .all_tasks (loop ), set ())
2768
2778
self ._register_task (task )
2769
- self .assertEqual (asyncio .all_tasks (loop ), {task })
2779
+ self .assertEqual (self .all_tasks (loop ), {task })
2770
2780
self ._unregister_task (task )
2771
2781
2772
2782
def test__register_task_3 (self ):
@@ -2780,9 +2790,9 @@ def done(self):
2780
2790
task = TaskLike ()
2781
2791
loop = mock .Mock ()
2782
2792
2783
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2793
+ self .assertEqual (self .all_tasks (loop ), set ())
2784
2794
self ._register_task (task )
2785
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2795
+ self .assertEqual (self .all_tasks (loop ), set ())
2786
2796
self ._unregister_task (task )
2787
2797
2788
2798
def test__enter_task (self ):
@@ -2833,20 +2843,21 @@ def test__unregister_task(self):
2833
2843
task .get_loop = lambda : loop
2834
2844
self ._register_task (task )
2835
2845
self ._unregister_task (task )
2836
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2846
+ self .assertEqual (self .all_tasks (loop ), set ())
2837
2847
2838
2848
def test__unregister_task_not_registered (self ):
2839
2849
task = mock .Mock ()
2840
2850
loop = mock .Mock ()
2841
2851
self ._unregister_task (task )
2842
- self .assertEqual (asyncio .all_tasks (loop ), set ())
2852
+ self .assertEqual (self .all_tasks (loop ), set ())
2843
2853
2844
2854
2845
2855
class PyIntrospectionTests (test_utils .TestCase , BaseTaskIntrospectionTests ):
2846
2856
_register_task = staticmethod (tasks ._py_register_task )
2847
2857
_unregister_task = staticmethod (tasks ._py_unregister_task )
2848
2858
_enter_task = staticmethod (tasks ._py_enter_task )
2849
2859
_leave_task = staticmethod (tasks ._py_leave_task )
2860
+ all_tasks = staticmethod (tasks ._py_all_tasks )
2850
2861
2851
2862
2852
2863
@unittest .skipUnless (hasattr (tasks , '_c_register_task' ),
@@ -2857,6 +2868,7 @@ class CIntrospectionTests(test_utils.TestCase, BaseTaskIntrospectionTests):
2857
2868
_unregister_task = staticmethod (tasks ._c_unregister_task )
2858
2869
_enter_task = staticmethod (tasks ._c_enter_task )
2859
2870
_leave_task = staticmethod (tasks ._c_leave_task )
2871
+ all_tasks = staticmethod (tasks ._c_all_tasks )
2860
2872
else :
2861
2873
_register_task = _unregister_task = _enter_task = _leave_task = None
2862
2874
0 commit comments