bpo-38107: Replace direct future and task contructor calls with factories in asyncio tests (GH-15928)

This commit is contained in:
Andrew Svetlov 2019-09-11 16:07:37 +03:00 committed by GitHub
parent 781266ebb6
commit 9aee90018a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 156 additions and 159 deletions

View file

@ -47,7 +47,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
return transport
def test_ctor(self):
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
tr = self.socket_transport(waiter=fut)
test_utils.run_briefly(self.loop)
self.assertIsNone(fut.result())
@ -62,7 +62,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
self.assertFalse(self.protocol.eof_received.called)
def test_loop_reading_data(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(b'data')
tr = self.socket_transport()
@ -72,7 +72,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
self.protocol.data_received.assert_called_with(b'data')
def test_loop_reading_no_data(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(b'')
tr = self.socket_transport()
@ -182,7 +182,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
m_log.warning.assert_called_with('socket.send() raised exception.')
def test_loop_writing_stop(self):
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
fut.set_result(b'data')
tr = self.socket_transport()
@ -191,7 +191,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
self.assertIsNone(tr._write_fut)
def test_loop_writing_closing(self):
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
fut.set_result(1)
tr = self.socket_transport()
@ -260,7 +260,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
def test_loop_writing_force_close(self):
exc_handler = mock.Mock()
self.loop.set_exception_handler(exc_handler)
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
fut.set_result(1)
self.proactor.send.return_value = fut
@ -303,7 +303,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
def test_write_eof_buffer(self):
tr = self.socket_transport()
f = asyncio.Future(loop=self.loop)
f = self.loop.create_future()
tr._loop._proactor.send.return_value = f
tr.write(b'data')
tr.write_eof()
@ -327,7 +327,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
def test_write_eof_buffer_write_pipe(self):
tr = _ProactorWritePipeTransport(self.loop, self.sock, self.protocol)
f = asyncio.Future(loop=self.loop)
f = self.loop.create_future()
tr._loop._proactor.send.return_value = f
tr.write(b'data')
tr.write_eof()
@ -352,7 +352,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr = self.socket_transport()
futures = []
for msg in [b'data1', b'data2', b'data3', b'data4', b'data5', b'']:
f = asyncio.Future(loop=self.loop)
f = self.loop.create_future()
f.set_result(msg)
futures.append(f)
@ -406,7 +406,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr = self.pause_writing_transport(high=4)
# write a large chunk, must pause writing
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
self.loop._proactor.send.return_value = fut
tr.write(b'large data')
self.loop._run_once()
@ -422,7 +422,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr = self.pause_writing_transport(high=4)
# first short write, the buffer is not full (3 <= 4)
fut1 = asyncio.Future(loop=self.loop)
fut1 = self.loop.create_future()
self.loop._proactor.send.return_value = fut1
tr.write(b'123')
self.loop._run_once()
@ -439,7 +439,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr = self.pause_writing_transport(high=4)
# first short write, the buffer is not full (1 <= 4)
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
self.loop._proactor.send.return_value = fut
tr.write(b'1')
self.loop._run_once()
@ -463,7 +463,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
# write a large chunk which completes immediately,
# it should not pause writing
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
fut.set_result(None)
self.loop._proactor.send.return_value = fut
tr.write(b'very large data')
@ -496,7 +496,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
return transport
def test_ctor(self):
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
tr = self.socket_transport(waiter=fut)
test_utils.run_briefly(self.loop)
self.assertIsNone(fut.result())
@ -541,7 +541,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
tr = self.socket_transport()
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(b'data')
tr = self.socket_transport()
@ -558,7 +558,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
tr.set_protocol(buf_proto)
test_utils.run_briefly(self.loop)
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(4)
tr._read_fut = res
@ -591,7 +591,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
self.loop.call_exception_handler = mock.Mock()
self.protocol.buffer_updated.side_effect = LookupError()
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(10)
transport._read_fut = res
transport._loop_reading(res)
@ -601,7 +601,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
self.assertTrue(self.protocol.buffer_updated.called)
def test_loop_eof_received_error(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(0)
self.protocol.eof_received.side_effect = LookupError()
@ -617,7 +617,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
self.assertTrue(tr._fatal_error.called)
def test_loop_reading_data(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(4)
tr = self.socket_transport()
@ -627,7 +627,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
self.protocol.buffer_updated.assert_called_with(4)
def test_loop_reading_no_data(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result(0)
tr = self.socket_transport()
@ -691,7 +691,7 @@ class ProactorSocketTransportBufferedProtoTests(test_utils.TestCase):
tr = self.socket_transport()
futures = []
for msg in [10, 20, 30, 40, 0]:
f = asyncio.Future(loop=self.loop)
f = self.loop.create_future()
f.set_result(msg)
futures.append(f)
@ -1044,7 +1044,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
loop = call_soon.call_args[0][0]
# cancelled
fut = asyncio.Future(loop=self.loop)
fut = self.loop.create_future()
fut.cancel()
loop(fut)
self.assertTrue(self.sock.close.called)
@ -1094,7 +1094,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
close_transport(tr)
def test_datagram_loop_reading_data(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result((b'data', ('127.0.0.1', 12068)))
tr = self.datagram_transport()
@ -1105,7 +1105,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
close_transport(tr)
def test_datagram_loop_reading_no_data(self):
res = asyncio.Future(loop=self.loop)
res = self.loop.create_future()
res.set_result((b'', ('127.0.0.1', 12068)))
tr = self.datagram_transport()