summaryrefslogtreecommitdiff
path: root/Lib/test/test_asyncio/test_futures.py
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2020-05-15 16:55:50 -0700
committerGitHub <noreply@github.com>2020-05-15 16:55:50 -0700
commit1ce5841eca6d96b1b1e8c213d04f2e92b1619bb5 (patch)
tree9fe492d885e1a0d660be4d96fb92b5f563aec99e /Lib/test/test_asyncio/test_futures.py
parentfe1176e882393b6d3e6a6cfa5ca23657f0b3b4a9 (diff)
downloadcpython-git-1ce5841eca6d96b1b1e8c213d04f2e92b1619bb5.tar.gz
bpo-31033: Add a msg argument to Future.cancel() and Task.cancel() (GH-19979)
Diffstat (limited to 'Lib/test/test_asyncio/test_futures.py')
-rw-r--r--Lib/test/test_asyncio/test_futures.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index ee5edd5bd3..ec00896cc6 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -201,6 +201,27 @@ class BaseFutureTests:
self.assertFalse(fut.cancelled())
self.assertFalse(fut.done())
+ def test_future_cancel_message_getter(self):
+ f = self._new_future(loop=self.loop)
+ self.assertTrue(hasattr(f, '_cancel_message'))
+ self.assertEqual(f._cancel_message, None)
+
+ f.cancel('my message')
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(f)
+ self.assertEqual(f._cancel_message, 'my message')
+
+ def test_future_cancel_message_setter(self):
+ f = self._new_future(loop=self.loop)
+ f.cancel('my message')
+ f._cancel_message = 'my new message'
+ self.assertEqual(f._cancel_message, 'my new message')
+
+ # Also check that the value is used for cancel().
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(f)
+ self.assertEqual(f._cancel_message, 'my new message')
+
def test_cancel(self):
f = self._new_future(loop=self.loop)
self.assertTrue(f.cancel())