Skip to content

Commit df0e543

Browse files
committed
Silence asyncio warnings in test_tasks.py
1 parent 2e0f3a3 commit df0e543

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

tests/test_tasks.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ def format_coroutine(qualname, state, src, source_traceback, generator=False):
2727
return 'coro=<%s() %s at %s>' % (qualname, state, src)
2828

2929

30+
try:
31+
all_tasks = asyncio.all_tasks
32+
except AttributeError:
33+
all_tasks = asyncio.Task.all_tasks
34+
35+
36+
try:
37+
current_task = asyncio.current_task
38+
except AttributeError:
39+
current_task = asyncio.Task.current_task
40+
41+
3042
class _TestTasks:
3143

3244
def test_task_basics(self):
@@ -88,7 +100,7 @@ def task():
88100
return 12
89101

90102
t = self.create_task(task())
91-
self.assertEqual(asyncio.Task.all_tasks(loop=self.loop), {t})
103+
self.assertEqual(all_tasks(loop=self.loop), {t})
92104
tb.run_briefly(self.loop)
93105

94106
f.cancel()
@@ -239,42 +251,42 @@ def wait_for_future():
239251
self.assertFalse(fut.done())
240252

241253
def test_task_current_task(self):
242-
self.assertIsNone(asyncio.Task.current_task(loop=self.loop))
254+
self.assertIsNone(current_task(loop=self.loop))
243255

244256
@asyncio.coroutine
245257
def coro(loop):
246-
self.assertTrue(asyncio.Task.current_task(loop=loop) is task)
258+
self.assertTrue(current_task(loop=loop) is task)
247259

248260
task = self.create_task(coro(self.loop))
249261
self.loop.run_until_complete(task)
250-
self.assertIsNone(asyncio.Task.current_task(loop=self.loop))
262+
self.assertIsNone(current_task(loop=self.loop))
251263

252264
def test_task_current_task_with_interleaving_tasks(self):
253-
self.assertIsNone(asyncio.Task.current_task(loop=self.loop))
265+
self.assertIsNone(current_task(loop=self.loop))
254266

255267
fut1 = self.create_future()
256268
fut2 = self.create_future()
257269

258270
@asyncio.coroutine
259271
def coro1(loop):
260-
self.assertTrue(asyncio.Task.current_task(loop=loop) is task1)
272+
self.assertTrue(current_task(loop=loop) is task1)
261273
yield from fut1
262-
self.assertTrue(asyncio.Task.current_task(loop=loop) is task1)
274+
self.assertTrue(current_task(loop=loop) is task1)
263275
fut2.set_result(True)
264276

265277
@asyncio.coroutine
266278
def coro2(loop):
267-
self.assertTrue(asyncio.Task.current_task(loop=loop) is task2)
279+
self.assertTrue(current_task(loop=loop) is task2)
268280
fut1.set_result(True)
269281
yield from fut2
270-
self.assertTrue(asyncio.Task.current_task(loop=loop) is task2)
282+
self.assertTrue(current_task(loop=loop) is task2)
271283

272284
task1 = self.create_task(coro1(self.loop))
273285
task2 = self.create_task(coro2(self.loop))
274286

275287
self.loop.run_until_complete(asyncio.wait((task1, task2),
276288
loop=self.loop))
277-
self.assertIsNone(asyncio.Task.current_task(loop=self.loop))
289+
self.assertIsNone(current_task(loop=self.loop))
278290

279291
def test_task_yield_future_passes_cancel(self):
280292
# Canceling outer() cancels inner() cancels waiter.

0 commit comments

Comments
 (0)