Skip to content

Commit

Permalink
bpo-31185: Fixed miscellaneous errors in asyncio speedup module. (pyt…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Sep 3, 2017
1 parent 8df44ee commit bca4939
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 219 deletions.
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 @@ -501,15 +534,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

0 comments on commit bca4939

Please sign in to comment.