summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-03 05:10:14 (GMT)
committerGitHub <noreply@github.com>2017-09-03 05:10:14 (GMT)
commitbca4939d806170c3ca5d05f23710d11a8f1669cf (patch)
tree104b11ed1cc4806358b0e6212c7934b2c844b092 /Lib/test/test_asyncio
parent8df44ee8e0fbdb390bd38eb88eb1ee4e2a10d355 (diff)
downloadcpython-bca4939d806170c3ca5d05f23710d11a8f1669cf.zip
cpython-bca4939d806170c3ca5d05f23710d11a8f1669cf.tar.gz
cpython-bca4939d806170c3ca5d05f23710d11a8f1669cf.tar.bz2
bpo-31185: Fixed miscellaneous errors in asyncio speedup module. (#3076)
Diffstat (limited to 'Lib/test/test_asyncio')
-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 f8f614f..4320a90 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())
@@ -501,15 +534,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():