summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_tasks.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-12 16:39:26 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-12 16:39:26 (GMT)
commit307bccc6ff6670c58f4c20421a29071ff710e6a3 (patch)
treee165b2e33505bcece03948112ca230af5d2d2688 /Lib/test/test_asyncio/test_tasks.py
parentf54432e2a16d445ed6fa142a9c5d8d23b11780b2 (diff)
downloadcpython-307bccc6ff6670c58f4c20421a29071ff710e6a3.zip
cpython-307bccc6ff6670c58f4c20421a29071ff710e6a3.tar.gz
cpython-307bccc6ff6670c58f4c20421a29071ff710e6a3.tar.bz2
asyncio: Tulip issue 173: Enhance repr(Handle) and repr(Task)
repr(Handle) is shorter for function: "foo" instead of "<function foo at 0x...>". It now also includes the source of the callback, filename and line number where it was defined, if available. repr(Task) now also includes the current position in the code, filename and line number, if available. If the coroutine (generator) is done, the line number is omitted and "done" is added.
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 45a0dc1..92eb9da 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -116,21 +116,30 @@ class TaskTests(unittest.TestCase):
yield from []
return 'abc'
+ filename, lineno = test_utils.get_function_source(notmuch)
+ src = "%s:%s" % (filename, lineno)
+
t = asyncio.Task(notmuch(), loop=self.loop)
t.add_done_callback(Dummy())
- self.assertEqual(repr(t), 'Task(<notmuch>)<PENDING, [Dummy()]>')
+ self.assertEqual(repr(t),
+ 'Task(<notmuch at %s>)<PENDING, [Dummy()]>' % src)
+
t.cancel() # Does not take immediate effect!
- self.assertEqual(repr(t), 'Task(<notmuch>)<CANCELLING, [Dummy()]>')
+ self.assertEqual(repr(t),
+ 'Task(<notmuch at %s>)<CANCELLING, [Dummy()]>' % src)
self.assertRaises(asyncio.CancelledError,
self.loop.run_until_complete, t)
- self.assertEqual(repr(t), 'Task(<notmuch>)<CANCELLED>')
+ self.assertEqual(repr(t),
+ 'Task(<notmuch done at %s>)<CANCELLED>' % filename)
+
t = asyncio.Task(notmuch(), loop=self.loop)
self.loop.run_until_complete(t)
- self.assertEqual(repr(t), "Task(<notmuch>)<result='abc'>")
+ self.assertEqual(repr(t),
+ "Task(<notmuch done at %s>)<result='abc'>" % filename)
def test_task_repr_custom(self):
@asyncio.coroutine
- def coro():
+ def notmuch():
pass
class T(asyncio.Future):
@@ -141,10 +150,14 @@ class TaskTests(unittest.TestCase):
def __repr__(self):
return super().__repr__()
- gen = coro()
+ gen = notmuch()
t = MyTask(gen, loop=self.loop)
- self.assertEqual(repr(t), 'T[](<coro>)')
- gen.close()
+ filename = gen.gi_code.co_filename
+ lineno = gen.gi_frame.f_lineno
+ # FIXME: check for the name "coro" instead of "notmuch" because
+ # @asyncio.coroutine drops the name of the wrapped function:
+ # http://bugs.python.org/issue21205
+ self.assertEqual(repr(t), 'T[](<coro at %s:%s>)' % (filename, lineno))
def test_task_basics(self):
@asyncio.coroutine