asyncio: Cleanup Future API

See https://github.com/python/asyncio/pull/292 for details.
This commit is contained in:
Yury Selivanov 2015-11-17 12:19:41 -05:00
parent 0013ccedd1
commit 5d7e3b6cd2
6 changed files with 49 additions and 40 deletions

View file

@ -174,11 +174,13 @@ class FutureTests(test_utils.TestCase):
'<Future cancelled>')
def test_copy_state(self):
from asyncio.futures import _copy_future_state
f = asyncio.Future(loop=self.loop)
f.set_result(10)
newf = asyncio.Future(loop=self.loop)
newf._copy_state(f)
_copy_future_state(f, newf)
self.assertTrue(newf.done())
self.assertEqual(newf.result(), 10)
@ -186,7 +188,7 @@ class FutureTests(test_utils.TestCase):
f_exception.set_exception(RuntimeError())
newf_exception = asyncio.Future(loop=self.loop)
newf_exception._copy_state(f_exception)
_copy_future_state(f_exception, newf_exception)
self.assertTrue(newf_exception.done())
self.assertRaises(RuntimeError, newf_exception.result)
@ -194,7 +196,7 @@ class FutureTests(test_utils.TestCase):
f_cancelled.cancel()
newf_cancelled = asyncio.Future(loop=self.loop)
newf_cancelled._copy_state(f_cancelled)
_copy_future_state(f_cancelled, newf_cancelled)
self.assertTrue(newf_cancelled.cancelled())
def test_iter(self):
@ -382,9 +384,10 @@ class FutureTests(test_utils.TestCase):
self.check_future_exception_never_retrieved(True)
def test_set_result_unless_cancelled(self):
from asyncio import futures
fut = asyncio.Future(loop=self.loop)
fut.cancel()
fut._set_result_unless_cancelled(2)
futures._set_result_unless_cancelled(fut, 2)
self.assertTrue(fut.cancelled())