MCPcopy Index your code
hub / github.com/python/cpython / test_task_repr

Method test_task_repr

Lib/test/test_asyncio/test_tasks.py:336–385  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

334 self.loop.run_until_complete(runner())
335
336 def test_task_repr(self):
337 self.loop.set_debug(False)
338
339 async def notmuch():
340 return 'abc'
341
342 # test coroutine function
343 self.assertEqual(notmuch.__name__, 'notmuch')
344 self.assertRegex(notmuch.__qualname__,
345 r'\w+.test_task_repr.<locals>.notmuch')
346 self.assertEqual(notmuch.__module__, __name__)
347
348 filename, lineno = test_utils.get_function_source(notmuch)
349 src = "%s:%s" % (filename, lineno)
350
351 # test coroutine object
352 gen = notmuch()
353 coro_qualname = 'BaseTaskTests.test_task_repr.<locals>.notmuch'
354 self.assertEqual(gen.__name__, 'notmuch')
355 self.assertEqual(gen.__qualname__, coro_qualname)
356
357 # test pending Task
358 t = self.new_task(self.loop, gen)
359 t.add_done_callback(Dummy())
360
361 coro = format_coroutine(coro_qualname, 'running', src,
362 t._source_traceback, generator=True)
363 self.assertEqual(repr(t),
364 "<Task pending name='TestTask' %s cb=[<Dummy>()]>" % coro)
365
366 # test cancelling Task
367 t.cancel() # Does not take immediate effect!
368 self.assertEqual(repr(t),
369 "<Task cancelling name='TestTask' %s cb=[<Dummy>()]>" % coro)
370
371 # test cancelled Task
372 self.assertRaises(asyncio.CancelledError,
373 self.loop.run_until_complete, t)
374 coro = format_coroutine(coro_qualname, 'done', src,
375 t._source_traceback)
376 self.assertEqual(repr(t),
377 "<Task cancelled name='TestTask' %s>" % coro)
378
379 # test finished Task
380 t = self.new_task(self.loop, notmuch())
381 self.loop.run_until_complete(t)
382 coro = format_coroutine(coro_qualname, 'done', src,
383 t._source_traceback)
384 self.assertEqual(repr(t),
385 "<Task finished name='TestTask' %s result='abc'>" % coro)
386
387 def test_task_repr_autogenerated(self):
388 async def notmuch():

Callers

nothing calls this directly

Calls 10

new_taskMethod · 0.95
format_coroutineFunction · 0.85
assertRegexMethod · 0.80
DummyClass · 0.70
set_debugMethod · 0.45
assertEqualMethod · 0.45
add_done_callbackMethod · 0.45
cancelMethod · 0.45
assertRaisesMethod · 0.45
run_until_completeMethod · 0.45

Tested by

no test coverage detected