summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2019-09-11 13:07:37 (GMT)
committerGitHub <noreply@github.com>2019-09-11 13:07:37 (GMT)
commit9aee90018a5213e3529768e0b873955d23f5e50b (patch)
tree36f9368f08981adac902adcbedd3223f6533c4c2 /Lib/test/test_asyncio
parent781266ebb60e7ac781a3e07030d92275721ff3cf (diff)
downloadcpython-9aee90018a5213e3529768e0b873955d23f5e50b.zip
cpython-9aee90018a5213e3529768e0b873955d23f5e50b.tar.gz
cpython-9aee90018a5213e3529768e0b873955d23f5e50b.tar.bz2
bpo-38107: Replace direct future and task contructor calls with factories in asyncio tests (GH-15928)
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py32
-rw-r--r--Lib/test/test_asyncio/test_events.py30
-rw-r--r--Lib/test/test_asyncio/test_locks.py76
-rw-r--r--Lib/test/test_asyncio/test_pep492.py2
-rw-r--r--Lib/test/test_asyncio/test_proactor_events.py48
-rw-r--r--Lib/test/test_asyncio/test_queues.py34
-rw-r--r--Lib/test/test_asyncio/test_selector_events.py10
-rw-r--r--Lib/test/test_asyncio/test_sock_lowlevel.py4
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py12
-rw-r--r--Lib/test/test_asyncio/test_streams.py34
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py5
-rw-r--r--Lib/test/test_asyncio/test_tasks.py24
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py4
13 files changed, 156 insertions, 159 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 08d4792..370e6a6 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -193,7 +193,7 @@ class BaseEventLoopTests(test_utils.TestCase):
self.loop.close()
# operation blocked when the loop is closed
- f = asyncio.Future(loop=self.loop)
+ f = self.loop.create_future()
self.assertRaises(RuntimeError, self.loop.run_forever)
self.assertRaises(RuntimeError, self.loop.run_until_complete, f)
@@ -324,7 +324,7 @@ class BaseEventLoopTests(test_utils.TestCase):
def test_thread(loop, debug, create_loop=False):
event = threading.Event()
- fut = asyncio.Future(loop=loop)
+ fut = loop.create_future()
loop.call_soon(event.set)
args = (loop, event, debug, create_loop, fut)
thread = threading.Thread(target=check_in_thread, args=args)
@@ -472,7 +472,7 @@ class BaseEventLoopTests(test_utils.TestCase):
self.loop.run_until_complete, 'blah')
def test_run_until_complete_loop(self):
- task = asyncio.Future(loop=self.loop)
+ task = self.loop.create_future()
other_loop = self.new_test_loop()
self.addCleanup(other_loop.close)
self.assertRaises(ValueError,
@@ -555,7 +555,7 @@ class BaseEventLoopTests(test_utils.TestCase):
# Test call_soon (events.Handle)
with mock.patch('asyncio.base_events.logger') as log:
- fut = asyncio.Future(loop=self.loop)
+ fut = self.loop.create_future()
self.loop.call_soon(zero_error, fut)
fut.add_done_callback(lambda fut: self.loop.stop())
self.loop.run_forever()
@@ -565,7 +565,7 @@ class BaseEventLoopTests(test_utils.TestCase):
# Test call_later (events.TimerHandle)
with mock.patch('asyncio.base_events.logger') as log:
- fut = asyncio.Future(loop=self.loop)
+ fut = self.loop.create_future()
self.loop.call_later(0.01, zero_error, fut)
fut.add_done_callback(lambda fut: self.loop.stop())
self.loop.run_forever()
@@ -996,7 +996,7 @@ class MyProto(asyncio.Protocol):
self.state = 'INITIAL'
self.nbytes = 0
if create_future:
- self.done = asyncio.Future()
+ self.done = asyncio.get_running_loop().create_future()
def connection_made(self, transport):
self.transport = transport
@@ -1026,7 +1026,7 @@ class MyDatagramProto(asyncio.DatagramProtocol):
self.state = 'INITIAL'
self.nbytes = 0
if create_future:
- self.done = asyncio.Future(loop=loop)
+ self.done = loop.create_future()
def connection_made(self, transport):
self.transport = transport
@@ -1071,7 +1071,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
(2, 1, 6, '', ('107.6.106.82', 80))]
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
idx = -1
errors = ['err1', 'err2']
@@ -1098,7 +1098,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
m_socket.socket.return_value = sock
def getaddrinfo(*args, **kw):
- fut = asyncio.Future(loop=self.loop)
+ fut = self.loop.create_future()
addr = (socket.AF_INET, socket.SOCK_STREAM, 0, '',
('127.0.0.1', 80))
fut.set_result([addr])
@@ -1190,7 +1190,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
return []
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
self.loop.getaddrinfo = getaddrinfo_task
coro = self.loop.create_connection(MyProto, 'example.com', 80)
@@ -1202,7 +1202,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
return [(2, 1, 6, '', ('107.6.106.82', 80))]
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
self.loop.getaddrinfo = getaddrinfo_task
self.loop.sock_connect = mock.Mock()
@@ -1218,7 +1218,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
(2, 1, 6, '', ('0.0.0.2', 80))]
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
self.loop.getaddrinfo = getaddrinfo_task
self.loop.sock_connect = mock.Mock()
@@ -1245,7 +1245,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
(2, 1, 6, '', ('0.0.0.2', 80))]
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
self.loop.getaddrinfo = getaddrinfo_task
self.loop.sock_connect = mock.Mock()
@@ -1377,7 +1377,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
return []
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
self.loop.getaddrinfo = getaddrinfo_task
coro = self.loop.create_connection(
@@ -1405,7 +1405,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
self.loop.getaddrinfo = mock.Mock()
def mock_getaddrinfo(*args, **kwds):
- f = asyncio.Future(loop=self.loop)
+ f = self.loop.create_future()
f.set_result([(socket.AF_INET, socket.SOCK_STREAM,
socket.SOL_TCP, '', ('1.2.3.4', 80))])
return f
@@ -1513,7 +1513,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
return []
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
self.loop.getaddrinfo = getaddrinfo_task
fut = self.loop.create_server(MyProto, '', 0)
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index bdc8613..7256758 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -82,8 +82,8 @@ class MyBaseProto(asyncio.Protocol):
self.state = 'INITIAL'
self.nbytes = 0
if loop is not None:
- self.connected = asyncio.Future(loop=loop)
- self.done = asyncio.Future(loop=loop)
+ self.connected = loop.create_future()
+ self.done = loop.create_future()
def connection_made(self, transport):
self.transport = transport
@@ -120,7 +120,7 @@ class MyDatagramProto(asyncio.DatagramProtocol):
self.state = 'INITIAL'
self.nbytes = 0
if loop is not None:
- self.done = asyncio.Future(loop=loop)
+ self.done = loop.create_future()
def connection_made(self, transport):
self.transport = transport
@@ -149,7 +149,7 @@ class MyReadPipeProto(asyncio.Protocol):
self.nbytes = 0
self.transport = None
if loop is not None:
- self.done = asyncio.Future(loop=loop)
+ self.done = loop.create_future()
def connection_made(self, transport):
self.transport = transport
@@ -180,7 +180,7 @@ class MyWritePipeProto(asyncio.BaseProtocol):
self.state = 'INITIAL'
self.transport = None
if loop is not None:
- self.done = asyncio.Future(loop=loop)
+ self.done = loop.create_future()
def connection_made(self, transport):
self.transport = transport
@@ -199,9 +199,9 @@ class MySubprocessProtocol(asyncio.SubprocessProtocol):
def __init__(self, loop):
self.state = 'INITIAL'
self.transport = None
- self.connected = asyncio.Future(loop=loop)
- self.completed = asyncio.Future(loop=loop)
- self.disconnects = {fd: asyncio.Future(loop=loop) for fd in range(3)}
+ self.connected = loop.create_future()
+ self.completed = loop.create_future()
+ self.disconnects = {fd: loop.create_future() for fd in range(3)}
self.data = {1: b'', 2: b''}
self.returncode = None
self.got_data = {1: asyncio.Event(loop=loop),
@@ -739,7 +739,7 @@ class EventLoopTestsMixin:
return [(family, socket.SOCK_STREAM, 6, '', (host, port, 0, 0))]
def getaddrinfo_task(*args, **kwds):
- return asyncio.Task(getaddrinfo(*args, **kwds), loop=self.loop)
+ return self.loop.create_task(getaddrinfo(*args, **kwds))
unique_hosts = set(hosts)
@@ -1095,7 +1095,7 @@ class EventLoopTestsMixin:
client, pr = self.loop.run_until_complete(f_c)
# extra info is available
- self.check_ssl_extra_info(client,peername=(host, port),
+ self.check_ssl_extra_info(client, peername=(host, port),
peercert=test_utils.PEERCERT)
# close connection
@@ -1105,7 +1105,7 @@ class EventLoopTestsMixin:
self.loop.run_until_complete(proto.done)
def test_create_server_sock(self):
- proto = asyncio.Future(loop=self.loop)
+ proto = self.loop.create_future()
class TestMyProto(MyProto):
def connection_made(self, transport):
@@ -1144,7 +1144,7 @@ class EventLoopTestsMixin:
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 not supported or enabled')
def test_create_server_dual_stack(self):
- f_proto = asyncio.Future(loop=self.loop)
+ f_proto = self.loop.create_future()
class TestMyProto(MyProto):
def connection_made(self, transport):
@@ -1173,7 +1173,7 @@ class EventLoopTestsMixin:
proto.transport.close()
client.close()
- f_proto = asyncio.Future(loop=self.loop)
+ f_proto = self.loop.create_future()
client = socket.socket(socket.AF_INET6)
client.connect(('::1', port))
client.send(b'xxx')
@@ -1588,7 +1588,7 @@ class EventLoopTestsMixin:
return res
start = time.monotonic()
- t = asyncio.Task(main(), loop=self.loop)
+ t = self.loop.create_task(main())
self.loop.run_forever()
elapsed = time.monotonic() - start
@@ -1674,7 +1674,7 @@ class EventLoopTestsMixin:
with self.assertRaises(RuntimeError):
self.loop.run_forever()
with self.assertRaises(RuntimeError):
- fut = asyncio.Future(loop=self.loop)
+ fut = self.loop.create_future()
self.loop.run_until_complete(fut)
with self.assertRaises(RuntimeError):
self.loop.call_soon(func)
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index a9953b4..9468e74 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -124,8 +124,8 @@ class LockTests(test_utils.TestCase):
result.append(3)
return True
- t1 = asyncio.Task(c1(result), loop=self.loop)
- t2 = asyncio.Task(c2(result), loop=self.loop)
+ t1 = self.loop.create_task(c1(result))
+ t2 = self.loop.create_task(c2(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
@@ -137,7 +137,7 @@ class LockTests(test_utils.TestCase):
test_utils.run_briefly(self.loop)
self.assertEqual([1], result)
- t3 = asyncio.Task(c3(result), loop=self.loop)
+ t3 = self.loop.create_task(c3(result))
lock.release()
test_utils.run_briefly(self.loop)
@@ -159,7 +159,7 @@ class LockTests(test_utils.TestCase):
lock = asyncio.Lock(loop=self.loop)
self.assertTrue(self.loop.run_until_complete(lock.acquire()))
- task = asyncio.Task(lock.acquire(), loop=self.loop)
+ task = self.loop.create_task(lock.acquire())
self.loop.call_soon(task.cancel)
self.assertRaises(
asyncio.CancelledError,
@@ -192,14 +192,14 @@ class LockTests(test_utils.TestCase):
finally:
lock.release()
- fa = asyncio.Future(loop=self.loop)
- ta = asyncio.Task(lockit('A', fa), loop=self.loop)
+ fa = self.loop.create_future()
+ ta = self.loop.create_task(lockit('A', fa))
test_utils.run_briefly(self.loop)
self.assertTrue(lock.locked())
- tb = asyncio.Task(lockit('B', None), loop=self.loop)
+ tb = self.loop.create_task(lockit('B', None))
test_utils.run_briefly(self.loop)
self.assertEqual(len(lock._waiters), 1)
- tc = asyncio.Task(lockit('C', None), loop=self.loop)
+ tc = self.loop.create_task(lockit('C', None))
test_utils.run_briefly(self.loop)
self.assertEqual(len(lock._waiters), 2)
@@ -267,17 +267,17 @@ class LockTests(test_utils.TestCase):
with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
- ta = asyncio.Task(lock.acquire(), loop=self.loop)
+ ta = self.loop.create_task(lock.acquire())
test_utils.run_briefly(self.loop)
self.assertTrue(lock.locked())
- tb = asyncio.Task(lock.acquire(), loop=self.loop)
+ tb = self.loop.create_task(lock.acquire())
test_utils.run_briefly(self.loop)
self.assertEqual(len(lock._waiters), 1)
# Create a second waiter, wake up the first, and cancel it.
# Without the fix, the second was not woken up.
- tc = asyncio.Task(lock.acquire(), loop=self.loop)
+ tc = self.loop.create_task(lock.acquire())
lock.release()
tb.cancel()
test_utils.run_briefly(self.loop)
@@ -405,13 +405,13 @@ class EventTests(test_utils.TestCase):
if await ev.wait():
result.append(3)
- t1 = asyncio.Task(c1(result), loop=self.loop)
- t2 = asyncio.Task(c2(result), loop=self.loop)
+ t1 = self.loop.create_task(c1(result))
+ t2 = self.loop.create_task(c2(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
- t3 = asyncio.Task(c3(result), loop=self.loop)
+ t3 = self.loop.create_task(c3(result))
ev.set()
test_utils.run_briefly(self.loop)
@@ -436,7 +436,7 @@ class EventTests(test_utils.TestCase):
with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
- wait = asyncio.Task(ev.wait(), loop=self.loop)
+ wait = self.loop.create_task(ev.wait())
self.loop.call_soon(wait.cancel)
self.assertRaises(
asyncio.CancelledError,
@@ -464,7 +464,7 @@ class EventTests(test_utils.TestCase):
result.append(1)
return True
- t = asyncio.Task(c1(result), loop=self.loop)
+ t = self.loop.create_task(c1(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
@@ -527,9 +527,9 @@ class ConditionTests(test_utils.TestCase):
result.append(3)
return True
- t1 = asyncio.Task(c1(result), loop=self.loop)
- t2 = asyncio.Task(c2(result), loop=self.loop)
- t3 = asyncio.Task(c3(result), loop=self.loop)
+ t1 = self.loop.create_task(c1(result))
+ t2 = self.loop.create_task(c2(result))
+ t3 = self.loop.create_task(c3(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
@@ -573,7 +573,7 @@ class ConditionTests(test_utils.TestCase):
cond = asyncio.Condition(loop=self.loop)
self.loop.run_until_complete(cond.acquire())
- wait = asyncio.Task(cond.wait(), loop=self.loop)
+ wait = self.loop.create_task(cond.wait())
self.loop.call_soon(wait.cancel)
self.assertRaises(
asyncio.CancelledError,
@@ -588,7 +588,7 @@ class ConditionTests(test_utils.TestCase):
self.loop.run_until_complete(cond.acquire())
self.assertTrue(cond.locked())
- wait_task = asyncio.Task(cond.wait(), loop=self.loop)
+ wait_task = self.loop.create_task(cond.wait())
test_utils.run_briefly(self.loop)
self.assertFalse(cond.locked())
@@ -657,7 +657,7 @@ class ConditionTests(test_utils.TestCase):
cond.release()
return True
- t = asyncio.Task(c1(result), loop=self.loop)
+ t = self.loop.create_task(c1(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
@@ -717,9 +717,9 @@ class ConditionTests(test_utils.TestCase):
cond.release()
return True
- t1 = asyncio.Task(c1(result), loop=self.loop)
- t2 = asyncio.Task(c2(result), loop=self.loop)
- t3 = asyncio.Task(c3(result), loop=self.loop)
+ t1 = self.loop.create_task(c1(result))
+ t2 = self.loop.create_task(c2(result))
+ t3 = self.loop.create_task(c3(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
@@ -764,8 +764,8 @@ class ConditionTests(test_utils.TestCase):
cond.release()
return True
- t1 = asyncio.Task(c1(result), loop=self.loop)
- t2 = asyncio.Task(c2(result), loop=self.loop)
+ t1 = self.loop.create_task(c1(result))
+ t2 = self.loop.create_task(c2(result))
test_utils.run_briefly(self.loop)
self.assertEqual([], result)
@@ -965,9 +965,9 @@ class SemaphoreTests(test_utils.TestCase):
result.append(4)
return True
- t1 = asyncio.Task(c1(result), loop=self.loop)
- t2 = asyncio.Task(c2(result), loop=self.loop)
- t3 = asyncio.Task(c3(result), loop=self.loop)
+ t1 = self.loop.create_task(c1(result))
+ t2 = self.loop.create_task(c2(result))
+ t3 = self.loop.create_task(c3(result))
test_utils.run_briefly(self.loop)
self.assertEqual([1], result)
@@ -975,7 +975,7 @@ class SemaphoreTests(test_utils.TestCase):
self.assertEqual(2, len(sem._waiters))
self.assertEqual(0, sem._value)
- t4 = asyncio.Task(c4(result), loop=self.loop)
+ t4 = self.loop.create_task(c4(result))
sem.release()
sem.release()
@@ -1003,7 +1003,7 @@ class SemaphoreTests(test_utils.TestCase):
sem = asyncio.Semaphore(loop=self.loop)
self.loop.run_until_complete(sem.acquire())
- acquire = asyncio.Task(sem.acquire(), loop=self.loop)
+ acquire = self.loop.create_task(sem.acquire())
self.loop.call_soon(acquire.cancel)
self.assertRaises(
asyncio.CancelledError,
@@ -1015,10 +1015,10 @@ class SemaphoreTests(test_utils.TestCase):
with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(value=0, loop=self.loop)
- t1 = asyncio.Task(sem.acquire(), loop=self.loop)
- t2 = asyncio.Task(sem.acquire(), loop=self.loop)
- t3 = asyncio.Task(sem.acquire(), loop=self.loop)
- t4 = asyncio.Task(sem.acquire(), loop=self.loop)
+ t1 = self.loop.create_task(sem.acquire())
+ t2 = self.loop.create_task(sem.acquire())
+ t3 = self.loop.create_task(sem.acquire())
+ t4 = self.loop.create_task(sem.acquire())
test_utils.run_briefly(self.loop)
@@ -1038,8 +1038,8 @@ class SemaphoreTests(test_utils.TestCase):
with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(value=0, loop=self.loop)
- t1 = asyncio.Task(sem.acquire(), loop=self.loop)
- t2 = asyncio.Task(sem.acquire(), loop=self.loop)
+ t1 = self.loop.create_task(sem.acquire())
+ t2 = self.loop.create_task(sem.acquire())
test_utils.run_briefly(self.loop)
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py
index dfb68b8..58a6094 100644
--- a/Lib/test/test_asyncio/test_pep492.py
+++ b/Lib/test/test_asyncio/test_pep492.py
@@ -206,7 +206,7 @@ class CoroutineTests(BaseTest):
async def runner():
coro = afunc()
- t = asyncio.Task(coro, loop=self.loop)
+ t = self.loop.create_task(coro)
try:
await asyncio.sleep(0)
await coro
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index b2fd606..c838c5c 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -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()
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
index 171176c..5c9aaa8 100644
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -44,7 +44,7 @@ class QueueBasicTests(_QueueTestBase):
async def add_getter():
q = asyncio.Queue(loop=loop)
# Start a task that waits to get.
- asyncio.Task(q.get(), loop=loop)
+ loop.create_task(q.get())
# Let it start waiting.
await asyncio.sleep(0.1)
self.assertTrue('_getters[1]' in fn(q))
@@ -58,7 +58,7 @@ class QueueBasicTests(_QueueTestBase):
q = asyncio.Queue(maxsize=1, loop=loop)
q.put_nowait(1)
# Start a task that waits to put.
- asyncio.Task(q.put(2), loop=loop)
+ loop.create_task(q.put(2))
# Let it start waiting.
await asyncio.sleep(0.1)
self.assertTrue('_putters[1]' in fn(q))
@@ -143,7 +143,7 @@ class QueueBasicTests(_QueueTestBase):
return True
async def test():
- t = asyncio.Task(putter(), loop=loop)
+ t = loop.create_task(putter())
await asyncio.sleep(0.01)
# The putter is blocked after putting two items.
@@ -181,7 +181,7 @@ class QueueGetTests(_QueueTestBase):
q = asyncio.Queue(1, loop=self.loop)
q.put_nowait(1)
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
q._putters.append(waiter)
res = self.loop.run_until_complete(q.get())
@@ -212,7 +212,7 @@ class QueueGetTests(_QueueTestBase):
async def queue_put():
loop.call_later(0.01, q.put_nowait, 1)
- queue_get_task = asyncio.Task(queue_get(), loop=loop)
+ queue_get_task = loop.create_task(queue_get())
await started.wait()
self.assertFalse(finished)
res = await queue_get_task
@@ -252,7 +252,7 @@ class QueueGetTests(_QueueTestBase):
return await asyncio.wait_for(q.get(), 0.051)
async def test():
- get_task = asyncio.Task(queue_get(), loop=loop)
+ get_task = loop.create_task(queue_get())
await asyncio.sleep(0.01) # let the task start
q.put_nowait(1)
return await get_task
@@ -264,8 +264,8 @@ class QueueGetTests(_QueueTestBase):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
- t1 = asyncio.Task(q.get(), loop=self.loop)
- t2 = asyncio.Task(q.get(), loop=self.loop)
+ t1 = self.loop.create_task(q.get())
+ t2 = self.loop.create_task(q.get())
test_utils.run_briefly(self.loop)
t1.cancel()
@@ -278,8 +278,8 @@ class QueueGetTests(_QueueTestBase):
def test_get_with_waiting_putters(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop, maxsize=1)
- asyncio.Task(q.put('a'), loop=self.loop)
- asyncio.Task(q.put('b'), loop=self.loop)
+ self.loop.create_task(q.put('a'))
+ self.loop.create_task(q.put('b'))
test_utils.run_briefly(self.loop)
self.assertEqual(self.loop.run_until_complete(q.get()), 'a')
self.assertEqual(self.loop.run_until_complete(q.get()), 'b')
@@ -361,7 +361,7 @@ class QueuePutTests(_QueueTestBase):
async def queue_get():
loop.call_later(0.01, q.get_nowait)
- queue_put_task = asyncio.Task(queue_put(), loop=loop)
+ queue_put_task = loop.create_task(queue_put())
await started.wait()
self.assertFalse(finished)
await queue_put_task
@@ -502,7 +502,7 @@ class QueuePutTests(_QueueTestBase):
async def test():
return await q.get()
- t = asyncio.Task(queue_put(), loop=self.loop)
+ t = self.loop.create_task(queue_put())
self.assertEqual(1, self.loop.run_until_complete(test()))
self.assertTrue(t.done())
self.assertTrue(t.result())
@@ -511,9 +511,9 @@ class QueuePutTests(_QueueTestBase):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop, maxsize=1)
- put_a = asyncio.Task(q.put('a'), loop=self.loop)
- put_b = asyncio.Task(q.put('b'), loop=self.loop)
- put_c = asyncio.Task(q.put('X'), loop=self.loop)
+ put_a = self.loop.create_task(q.put('a'))
+ put_b = self.loop.create_task(q.put('b'))
+ put_c = self.loop.create_task(q.put('X'))
test_utils.run_briefly(self.loop)
self.assertTrue(put_a.done())
@@ -531,7 +531,7 @@ class QueuePutTests(_QueueTestBase):
def test_put_with_waiting_getters(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
- t = asyncio.Task(q.get(), loop=self.loop)
+ t = self.loop.create_task(q.get())
test_utils.run_briefly(self.loop)
self.loop.run_until_complete(q.put('a'))
self.assertEqual(self.loop.run_until_complete(t), 'a')
@@ -665,7 +665,7 @@ class _QueueJoinTestMixin:
q.task_done()
async def test():
- tasks = [asyncio.Task(worker(), loop=self.loop)
+ tasks = [self.loop.create_task(worker())
for index in range(2)]
await q.join()
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
index 68b7853..1613c75 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -78,7 +78,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._add_writer = mock.Mock()
self.loop._remove_reader = mock.Mock()
self.loop._remove_writer = mock.Mock()
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
with test_utils.disable_logger():
transport = self.loop._make_ssl_transport(
m, asyncio.Protocol(), m, waiter)
@@ -154,7 +154,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop.close()
# operation blocked when the loop is closed
- f = asyncio.Future(loop=self.loop)
+ f = self.loop.create_future()
self.assertRaises(RuntimeError, self.loop.run_forever)
self.assertRaises(RuntimeError, self.loop.run_until_complete, f)
fd = 0
@@ -516,7 +516,7 @@ class SelectorSocketTransportTests(test_utils.TestCase):
return transport
def test_ctor(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
tr = self.socket_transport(waiter=waiter)
self.loop.run_until_complete(waiter)
@@ -525,7 +525,7 @@ class SelectorSocketTransportTests(test_utils.TestCase):
self.protocol.connection_made.assert_called_with(tr)
def test_ctor_with_waiter(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
self.socket_transport(waiter=waiter)
self.loop.run_until_complete(waiter)
@@ -911,7 +911,7 @@ class SelectorSocketTransportBufferedProtocolTests(test_utils.TestCase):
return transport
def test_ctor(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
tr = self.socket_transport(waiter=waiter)
self.loop.run_until_complete(waiter)
diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py
index 7b40a76..89c2af9 100644
--- a/Lib/test/test_asyncio/test_sock_lowlevel.py
+++ b/Lib/test/test_asyncio/test_sock_lowlevel.py
@@ -16,8 +16,8 @@ class MyProto(asyncio.Protocol):
self.state = 'INITIAL'
self.nbytes = 0
if loop is not None:
- self.connected = asyncio.Future(loop=loop)
- self.done = asyncio.Future(loop=loop)
+ self.connected = loop.create_future()
+ self.done = loop.create_future()
def connection_made(self, transport):
self.transport = transport
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index 9457bc9..c115e46 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -72,7 +72,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
ssl_handshake_timeout=-10)
def test_eof_received_waiter(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
self.connection_made(ssl_proto)
ssl_proto.eof_received()
@@ -83,7 +83,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
# From issue #363.
# _fatal_error() generates a NameError if sslproto.py
# does not import base_events.
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
# Temporarily turn off error logging so as not to spoil test output.
log_level = log.logger.getEffectiveLevel()
@@ -97,7 +97,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def test_connection_lost(self):
# From issue #472.
# yield from waiter hang if lost_connection was called.
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
self.connection_made(ssl_proto)
ssl_proto.connection_lost(ConnectionAbortedError)
@@ -106,7 +106,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def test_close_during_handshake(self):
# bpo-29743 Closing transport during handshake process leaks socket
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
transport = self.connection_made(ssl_proto)
@@ -116,7 +116,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
self.assertTrue(transport.abort.called)
def test_get_extra_info_on_closed_connection(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
self.assertIsNone(ssl_proto._get_extra_info('socket'))
default = object()
@@ -127,7 +127,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
self.assertIsNone(ssl_proto._get_extra_info('socket'))
def test_set_new_app_protocol(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
new_app_proto = asyncio.Protocol()
ssl_proto._app_transport.set_protocol(new_app_proto)
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 428c863..60fe52f 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -192,7 +192,7 @@ class StreamTests(test_utils.TestCase):
stream = asyncio.Stream(mode=asyncio.StreamMode.READ,
loop=self.loop,
_asyncio_internal=True)
- read_task = asyncio.Task(stream.read(30), loop=self.loop)
+ read_task = self.loop.create_task(stream.read(30))
def cb():
stream._feed_data(self.DATA)
@@ -220,7 +220,7 @@ class StreamTests(test_utils.TestCase):
stream = asyncio.Stream(mode=asyncio.StreamMode.READ,
loop=self.loop,
_asyncio_internal=True)
- read_task = asyncio.Task(stream.read(1024), loop=self.loop)
+ read_task = self.loop.create_task(stream.read(1024))
def cb():
stream._feed_eof()
@@ -235,7 +235,7 @@ class StreamTests(test_utils.TestCase):
stream = asyncio.Stream(mode=asyncio.StreamMode.READ,
loop=self.loop,
_asyncio_internal=True)
- read_task = asyncio.Task(stream.read(-1), loop=self.loop)
+ read_task = self.loop.create_task(stream.read(-1))
def cb():
stream._feed_data(b'chunk1\n')
@@ -288,7 +288,7 @@ class StreamTests(test_utils.TestCase):
loop=self.loop,
_asyncio_internal=True)
stream._feed_data(b'chunk1 ')
- read_task = asyncio.Task(stream.readline(), loop=self.loop)
+ read_task = self.loop.create_task(stream.readline())
def cb():
stream._feed_data(b'chunk2 ')
@@ -579,7 +579,7 @@ class StreamTests(test_utils.TestCase):
_asyncio_internal=True)
n = 2 * len(self.DATA)
- read_task = asyncio.Task(stream.readexactly(n), loop=self.loop)
+ read_task = self.loop.create_task(stream.readexactly(n))
def cb():
stream._feed_data(self.DATA)
@@ -606,7 +606,7 @@ class StreamTests(test_utils.TestCase):
loop=self.loop,
_asyncio_internal=True)
n = 2 * len(self.DATA)
- read_task = asyncio.Task(stream.readexactly(n), loop=self.loop)
+ read_task = self.loop.create_task(stream.readexactly(n))
def cb():
stream._feed_data(self.DATA)
@@ -652,8 +652,8 @@ class StreamTests(test_utils.TestCase):
async def set_err():
stream._set_exception(ValueError())
- t1 = asyncio.Task(stream.readline(), loop=self.loop)
- t2 = asyncio.Task(set_err(), loop=self.loop)
+ t1 = self.loop.create_task(stream.readline())
+ t2 = self.loop.create_task(set_err())
self.loop.run_until_complete(asyncio.wait([t1, t2]))
@@ -664,7 +664,7 @@ class StreamTests(test_utils.TestCase):
loop=self.loop,
_asyncio_internal=True)
- t = asyncio.Task(stream.readline(), loop=self.loop)
+ t = self.loop.create_task(stream.readline())
test_utils.run_briefly(self.loop)
t.cancel()
test_utils.run_briefly(self.loop)
@@ -735,8 +735,7 @@ class StreamTests(test_utils.TestCase):
server = MyServer(self.loop)
with self.assertWarns(DeprecationWarning):
addr = server.start()
- msg = self.loop.run_until_complete(asyncio.Task(client(addr),
- loop=self.loop))
+ msg = self.loop.run_until_complete(self.loop.create_task(client(addr)))
server.stop()
self.assertEqual(msg, b"hello world!\n")
@@ -744,8 +743,7 @@ class StreamTests(test_utils.TestCase):
server = MyServer(self.loop)
with self.assertWarns(DeprecationWarning):
addr = server.start_callback()
- msg = self.loop.run_until_complete(asyncio.Task(client(addr),
- loop=self.loop))
+ msg = self.loop.run_until_complete(self.loop.create_task(client(addr)))
server.stop()
self.assertEqual(msg, b"hello world!\n")
@@ -810,8 +808,8 @@ class StreamTests(test_utils.TestCase):
server = MyServer(self.loop, path)
with self.assertWarns(DeprecationWarning):
server.start()
- msg = self.loop.run_until_complete(asyncio.Task(client(path),
- loop=self.loop))
+ msg = self.loop.run_until_complete(
+ self.loop.create_task(client(path)))
server.stop()
self.assertEqual(msg, b"hello world!\n")
@@ -820,8 +818,8 @@ class StreamTests(test_utils.TestCase):
server = MyServer(self.loop, path)
with self.assertWarns(DeprecationWarning):
server.start_callback()
- msg = self.loop.run_until_complete(asyncio.Task(client(path),
- loop=self.loop))
+ msg = self.loop.run_until_complete(
+ self.loop.create_task(client(path)))
server.stop()
self.assertEqual(msg, b"hello world!\n")
@@ -1016,7 +1014,7 @@ os.close(fd)
stream = asyncio.Stream(mode=asyncio.StreamMode.READ,
loop=self.loop,
_asyncio_internal=True)
- stream._waiter = asyncio.Future(loop=self.loop)
+ stream._waiter = self.loop.create_future()
self.assertRegex(
repr(stream),
r"<Stream .+ waiter=<Future pending[\S ]*>>")
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index b9578b2..2cfe657 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -43,7 +43,6 @@ class SubprocessTransportTests(test_utils.TestCase):
self.loop = self.new_test_loop()
self.set_event_loop(self.loop)
-
def create_transport(self, waiter=None):
protocol = mock.Mock()
protocol.connection_made._is_coroutine = False
@@ -54,7 +53,7 @@ class SubprocessTransportTests(test_utils.TestCase):
return (transport, protocol)
def test_proc_exited(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
transport, protocol = self.create_transport(waiter)
transport._process_exited(6)
self.loop.run_until_complete(waiter)
@@ -80,7 +79,7 @@ class SubprocessTransportTests(test_utils.TestCase):
transport.close()
def test_subprocess_repr(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
transport, protocol = self.create_transport(waiter)
transport._process_exited(6)
self.loop.run_until_complete(waiter)
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 323c090..3fbb2a1 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2660,7 +2660,7 @@ class CTask_Future_Tests(test_utils.TestCase):
try:
fut = Fut(loop=self.loop)
self.loop.call_later(0.1, fut.set_result, 1)
- task = asyncio.Task(coro(), loop=self.loop)
+ task = self.loop.create_task(coro())
res = self.loop.run_until_complete(task)
finally:
self.loop.close()
@@ -2878,7 +2878,7 @@ class GatherTestsBase:
test_utils.run_briefly(loop)
def _check_success(self, **kwargs):
- a, b, c = [asyncio.Future(loop=self.one_loop) for i in range(3)]
+ a, b, c = [self.one_loop.create_future() for i in range(3)]
fut = asyncio.gather(*self.wrap_futures(a, b, c), **kwargs)
cb = test_utils.MockCallback()
fut.add_done_callback(cb)
@@ -2900,7 +2900,7 @@ class GatherTestsBase:
self._check_success(return_exceptions=True)
def test_one_exception(self):
- a, b, c, d, e = [asyncio.Future(loop=self.one_loop) for i in range(5)]
+ a, b, c, d, e = [self.one_loop.create_future() for i in range(5)]
fut = asyncio.gather(*self.wrap_futures(a, b, c, d, e))
cb = test_utils.MockCallback()
fut.add_done_callback(cb)
@@ -2918,7 +2918,7 @@ class GatherTestsBase:
e.exception()
def test_return_exceptions(self):
- a, b, c, d = [asyncio.Future(loop=self.one_loop) for i in range(4)]
+ a, b, c, d = [self.one_loop.create_future() for i in range(4)]
fut = asyncio.gather(*self.wrap_futures(a, b, c, d),
return_exceptions=True)
cb = test_utils.MockCallback()
@@ -2991,15 +2991,15 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
self._check_empty_sequence(iter(""))
def test_constructor_heterogenous_futures(self):
- fut1 = asyncio.Future(loop=self.one_loop)
- fut2 = asyncio.Future(loop=self.other_loop)
+ fut1 = self.one_loop.create_future()
+ fut2 = self.other_loop.create_future()
with self.assertRaises(ValueError):
asyncio.gather(fut1, fut2)
with self.assertRaises(ValueError):
asyncio.gather(fut1, loop=self.other_loop)
def test_constructor_homogenous_futures(self):
- children = [asyncio.Future(loop=self.other_loop) for i in range(3)]
+ children = [self.other_loop.create_future() for i in range(3)]
fut = asyncio.gather(*children)
self.assertIs(fut._loop, self.other_loop)
self._run_loop(self.other_loop)
@@ -3010,7 +3010,7 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
self.assertFalse(fut.done())
def test_one_cancellation(self):
- a, b, c, d, e = [asyncio.Future(loop=self.one_loop) for i in range(5)]
+ a, b, c, d, e = [self.one_loop.create_future() for i in range(5)]
fut = asyncio.gather(a, b, c, d, e)
cb = test_utils.MockCallback()
fut.add_done_callback(cb)
@@ -3028,7 +3028,7 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
e.exception()
def test_result_exception_one_cancellation(self):
- a, b, c, d, e, f = [asyncio.Future(loop=self.one_loop)
+ a, b, c, d, e, f = [self.one_loop.create_future()
for i in range(6)]
fut = asyncio.gather(a, b, c, d, e, f, return_exceptions=True)
cb = test_utils.MockCallback()
@@ -3094,7 +3094,7 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
def test_cancellation_broadcast(self):
# Cancelling outer() cancels all children.
proof = 0
- waiter = asyncio.Future(loop=self.one_loop)
+ waiter = self.one_loop.create_future()
async def inner():
nonlocal proof
@@ -3130,8 +3130,8 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
await f
raise RuntimeError('should not be ignored')
- a = asyncio.Future(loop=self.one_loop)
- b = asyncio.Future(loop=self.one_loop)
+ a = self.one_loop.create_future()
+ b = self.one_loop.create_future()
async def outer():
await asyncio.gather(inner(a), inner(b), loop=self.one_loop)
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 1daa870..02ce7e8 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -669,7 +669,7 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
return transport
def test_ctor(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
tr = self.read_pipe_transport(waiter=waiter)
self.loop.run_until_complete(waiter)
@@ -819,7 +819,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
return transport
def test_ctor(self):
- waiter = asyncio.Future(loop=self.loop)
+ waiter = self.loop.create_future()
tr = self.write_pipe_transport(waiter=waiter)
self.loop.run_until_complete(waiter)