Skip to content

bpo-31185: Fixed miscellaneous errors in asyncio speedup module. (#3076) #3269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def test_ensure_future(self):

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()
Expand Down Expand Up @@ -147,6 +147,39 @@ def test_constructor_positional(self):
# 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())
Expand Down Expand Up @@ -499,15 +532,11 @@ def __del__(self):
@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():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed miscellaneous errors in asyncio speedup module.
Loading