@@ -92,28 +92,28 @@ def notmuch():
9292 loop .run_until_complete (t )
9393 loop .close ()
9494
95- def test_async_coroutine (self ):
95+ def test_ensure_future_coroutine (self ):
9696 @asyncio .coroutine
9797 def notmuch ():
9898 return 'ok'
99- t = asyncio .async (notmuch (), loop = self .loop )
99+ t = asyncio .ensure_future (notmuch (), loop = self .loop )
100100 self .loop .run_until_complete (t )
101101 self .assertTrue (t .done ())
102102 self .assertEqual (t .result (), 'ok' )
103103 self .assertIs (t ._loop , self .loop )
104104
105105 loop = asyncio .new_event_loop ()
106106 self .set_event_loop (loop )
107- t = asyncio .async (notmuch (), loop = loop )
107+ t = asyncio .ensure_future (notmuch (), loop = loop )
108108 self .assertIs (t ._loop , loop )
109109 loop .run_until_complete (t )
110110 loop .close ()
111111
112- def test_async_future (self ):
112+ def test_ensure_future_future (self ):
113113 f_orig = asyncio .Future (loop = self .loop )
114114 f_orig .set_result ('ko' )
115115
116- f = asyncio .async (f_orig )
116+ f = asyncio .ensure_future (f_orig )
117117 self .loop .run_until_complete (f )
118118 self .assertTrue (f .done ())
119119 self .assertEqual (f .result (), 'ko' )
@@ -123,19 +123,19 @@ def test_async_future(self):
123123 self .set_event_loop (loop )
124124
125125 with self .assertRaises (ValueError ):
126- f = asyncio .async (f_orig , loop = loop )
126+ f = asyncio .ensure_future (f_orig , loop = loop )
127127
128128 loop .close ()
129129
130- f = asyncio .async (f_orig , loop = self .loop )
130+ f = asyncio .ensure_future (f_orig , loop = self .loop )
131131 self .assertIs (f , f_orig )
132132
133- def test_async_task (self ):
133+ def test_ensure_future_task (self ):
134134 @asyncio .coroutine
135135 def notmuch ():
136136 return 'ok'
137137 t_orig = asyncio .Task (notmuch (), loop = self .loop )
138- t = asyncio .async (t_orig )
138+ t = asyncio .ensure_future (t_orig )
139139 self .loop .run_until_complete (t )
140140 self .assertTrue (t .done ())
141141 self .assertEqual (t .result (), 'ok' )
@@ -145,16 +145,22 @@ def notmuch():
145145 self .set_event_loop (loop )
146146
147147 with self .assertRaises (ValueError ):
148- t = asyncio .async (t_orig , loop = loop )
148+ t = asyncio .ensure_future (t_orig , loop = loop )
149149
150150 loop .close ()
151151
152- t = asyncio .async (t_orig , loop = self .loop )
152+ t = asyncio .ensure_future (t_orig , loop = self .loop )
153153 self .assertIs (t , t_orig )
154154
155- def test_async_neither (self ):
155+ def test_ensure_future_neither (self ):
156156 with self .assertRaises (TypeError ):
157- asyncio .async ('ok' )
157+ asyncio .ensure_future ('ok' )
158+
159+ def test_async_warning (self ):
160+ f = asyncio .Future (loop = self .loop )
161+ with self .assertWarnsRegex (DeprecationWarning ,
162+ 'function is deprecated, use ensure_' ):
163+ self .assertIs (f , asyncio .async (f ))
158164
159165 def test_task_repr (self ):
160166 self .loop .set_debug (False )
@@ -1420,7 +1426,7 @@ def outer():
14201426 else :
14211427 proof += 10
14221428
1423- f = asyncio .async (outer (), loop = self .loop )
1429+ f = asyncio .ensure_future (outer (), loop = self .loop )
14241430 test_utils .run_briefly (self .loop )
14251431 f .cancel ()
14261432 self .loop .run_until_complete (f )
@@ -1445,7 +1451,7 @@ def outer():
14451451 d , p = yield from asyncio .wait ([inner ()], loop = self .loop )
14461452 proof += 100
14471453
1448- f = asyncio .async (outer (), loop = self .loop )
1454+ f = asyncio .ensure_future (outer (), loop = self .loop )
14491455 test_utils .run_briefly (self .loop )
14501456 f .cancel ()
14511457 self .assertRaises (
@@ -1501,7 +1507,7 @@ def outer():
15011507 yield from asyncio .shield (inner (), loop = self .loop )
15021508 proof += 100
15031509
1504- f = asyncio .async (outer (), loop = self .loop )
1510+ f = asyncio .ensure_future (outer (), loop = self .loop )
15051511 test_utils .run_briefly (self .loop )
15061512 f .cancel ()
15071513 with self .assertRaises (asyncio .CancelledError ):
@@ -1668,7 +1674,7 @@ def kill_me(loop):
16681674
16691675 # schedule the task
16701676 coro = kill_me (self .loop )
1671- task = asyncio .async (coro , loop = self .loop )
1677+ task = asyncio .ensure_future (coro , loop = self .loop )
16721678 self .assertEqual (asyncio .Task .all_tasks (loop = self .loop ), {task })
16731679
16741680 # execute the task so it waits for future
@@ -1996,8 +2002,8 @@ def inner():
19962002 yield from waiter
19972003 proof += 1
19982004
1999- child1 = asyncio .async (inner (), loop = self .one_loop )
2000- child2 = asyncio .async (inner (), loop = self .one_loop )
2005+ child1 = asyncio .ensure_future (inner (), loop = self .one_loop )
2006+ child2 = asyncio .ensure_future (inner (), loop = self .one_loop )
20012007 gatherer = None
20022008
20032009 @asyncio .coroutine
@@ -2007,7 +2013,7 @@ def outer():
20072013 yield from gatherer
20082014 proof += 100
20092015
2010- f = asyncio .async (outer (), loop = self .one_loop )
2016+ f = asyncio .ensure_future (outer (), loop = self .one_loop )
20112017 test_utils .run_briefly (self .one_loop )
20122018 self .assertTrue (f .cancel ())
20132019 with self .assertRaises (asyncio .CancelledError ):
@@ -2034,7 +2040,7 @@ def inner(f):
20342040 def outer ():
20352041 yield from asyncio .gather (inner (a ), inner (b ), loop = self .one_loop )
20362042
2037- f = asyncio .async (outer (), loop = self .one_loop )
2043+ f = asyncio .ensure_future (outer (), loop = self .one_loop )
20382044 test_utils .run_briefly (self .one_loop )
20392045 a .set_result (None )
20402046 test_utils .run_briefly (self .one_loop )
0 commit comments