diff options
author | Yury Selivanov <yury@magic.io> | 2016-11-07 21:00:50 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-11-07 21:00:50 (GMT) |
commit | 49d6b8c0c3124e94728dd44aafc33becfb14415b (patch) | |
tree | c32c42dc11b85a2a083cc1cf4497034e298129b2 /Lib/test/test_asyncio | |
parent | 3b3a141a83a1e9141cecfdc1d2ee661f253b030c (diff) | |
download | cpython-49d6b8c0c3124e94728dd44aafc33becfb14415b.zip cpython-49d6b8c0c3124e94728dd44aafc33becfb14415b.tar.gz cpython-49d6b8c0c3124e94728dd44aafc33becfb14415b.tar.bz2 |
Issue #28634: Fix asyncio.isfuture() to support mocks
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_futures.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index 153b8ed..c306b77 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -101,6 +101,29 @@ class FutureTests(test_utils.TestCase): self.loop = self.new_test_loop() self.addCleanup(self.loop.close) + def test_isfuture(self): + class MyFuture: + _asyncio_future_blocking = None + + def __init__(self): + self._asyncio_future_blocking = False + + self.assertFalse(asyncio.isfuture(MyFuture)) + self.assertTrue(asyncio.isfuture(MyFuture())) + + self.assertFalse(asyncio.isfuture(1)) + self.assertFalse(asyncio.isfuture(asyncio.Future)) + + # As `isinstance(Mock(), Future)` returns `False` + self.assertFalse(asyncio.isfuture(mock.Mock())) + + # As `isinstance(Mock(Future), Future)` returns `True` + self.assertTrue(asyncio.isfuture(mock.Mock(asyncio.Future))) + + f = asyncio.Future(loop=self.loop) + self.assertTrue(asyncio.isfuture(f)) + f.cancel() + def test_initial_state(self): f = asyncio.Future(loop=self.loop) self.assertFalse(f.cancelled()) |