From bca4939d806170c3ca5d05f23710d11a8f1669cf Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 3 Sep 2017 08:10:14 +0300 Subject: bpo-31185: Fixed miscellaneous errors in asyncio speedup module. (#3076) --- Lib/test/test_asyncio/test_futures.py | 45 ++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'Lib/test/test_asyncio/test_futures.py') diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index f8f614f1c3..4320a901f4 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(): -- cgit v1.2.1