summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-03 06:24:32 (GMT)
committerGitHub <noreply@github.com>2017-09-03 06:24:32 (GMT)
commit98bbeb78e06d5756491705920e72f9721850c727 (patch)
tree05b8507212904b750d10a9430b391f6baee336fd /Lib/test
parent58521fdba1657f6553a1ead5cbaa100967a167b3 (diff)
downloadcpython-98bbeb78e06d5756491705920e72f9721850c727.zip
cpython-98bbeb78e06d5756491705920e72f9721850c727.tar.gz
cpython-98bbeb78e06d5756491705920e72f9721850c727.tar.bz2
bpo-31185: Fixed miscellaneous errors in asyncio speedup module. (#3076) (#3269)
(cherry picked from commit bca4939d806170c3ca5d05f23710d11a8f1669cf)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_futures.py45
1 files changed, 37 insertions, 8 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index ebedfec..a06059d 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -100,8 +100,8 @@ class DuckTests(test_utils.TestCase):
class BaseFutureTests:
- def _new_future(self, loop=None):
- raise NotImplementedError
+ def _new_future(self, *args, **kwargs):
+ return self.cls(*args, **kwargs)
def setUp(self):
super().setUp()
@@ -147,6 +147,39 @@ class BaseFutureTests:
# Make sure Future doesn't accept a positional argument
self.assertRaises(TypeError, self._new_future, 42)
+ def test_uninitialized(self):
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ self.assertRaises(asyncio.InvalidStateError, fut.result)
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ self.assertRaises(asyncio.InvalidStateError, fut.exception)
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ with self.assertRaises((RuntimeError, AttributeError)):
+ fut.set_result(None)
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ with self.assertRaises((RuntimeError, AttributeError)):
+ fut.set_exception(Exception)
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ with self.assertRaises((RuntimeError, AttributeError)):
+ fut.cancel()
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ with self.assertRaises((RuntimeError, AttributeError)):
+ fut.add_done_callback(lambda f: None)
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ with self.assertRaises((RuntimeError, AttributeError)):
+ fut.remove_done_callback(lambda f: None)
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ with self.assertRaises((RuntimeError, AttributeError)):
+ fut._schedule_callbacks()
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ try:
+ repr(fut)
+ except AttributeError:
+ pass
+ fut = self.cls.__new__(self.cls, loop=self.loop)
+ fut.cancelled()
+ fut.done()
+ iter(fut)
+
def test_cancel(self):
f = self._new_future(loop=self.loop)
self.assertTrue(f.cancel())
@@ -499,15 +532,11 @@ class BaseFutureTests:
@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
class CFutureTests(BaseFutureTests, test_utils.TestCase):
-
- def _new_future(self, *args, **kwargs):
- return futures._CFuture(*args, **kwargs)
+ cls = getattr(futures, '_CFuture')
class PyFutureTests(BaseFutureTests, test_utils.TestCase):
-
- def _new_future(self, *args, **kwargs):
- return futures._PyFuture(*args, **kwargs)
+ cls = futures._PyFuture
class BaseFutureDoneCallbackTests():