mirror of
https://github.com/python/cpython.git
synced 2025-08-14 13:59:20 +00:00
bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [locks] (GH-13920)
This PR deprecate explicit loop parameters in all public asyncio APIs
This issues is split to be easier to review.
Third step: locks.py
https://bugs.python.org/issue36373
(cherry picked from commit 537877d85d
)
Co-authored-by: Emmanuel Arias <emmanuelarias30@gmail.com>
This commit is contained in:
parent
ab74e52f76
commit
bb8fc8bd30
7 changed files with 419 additions and 265 deletions
|
@ -59,6 +59,9 @@ Lock
|
|||
finally:
|
||||
lock.release()
|
||||
|
||||
.. deprecated-removed:: 3.8 3.10
|
||||
The *loop* parameter.
|
||||
|
||||
.. coroutinemethod:: acquire()
|
||||
|
||||
Acquire the lock.
|
||||
|
@ -101,6 +104,10 @@ Event
|
|||
:meth:`clear` method. The :meth:`wait` method blocks until the
|
||||
flag is set to *true*. The flag is set to *false* initially.
|
||||
|
||||
|
||||
.. deprecated-removed:: 3.8 3.10
|
||||
The *loop* parameter.
|
||||
|
||||
.. _asyncio_example_sync_event:
|
||||
|
||||
Example::
|
||||
|
@ -173,6 +180,10 @@ Condition
|
|||
``None``. In the latter case a new Lock object is created
|
||||
automatically.
|
||||
|
||||
|
||||
.. deprecated-removed:: 3.8 3.10
|
||||
The *loop* parameter.
|
||||
|
||||
The preferred way to use a Condition is an :keyword:`async with`
|
||||
statement::
|
||||
|
||||
|
@ -269,6 +280,10 @@ Semaphore
|
|||
internal counter (``1`` by default). If the given value is
|
||||
less than ``0`` a :exc:`ValueError` is raised.
|
||||
|
||||
|
||||
.. deprecated-removed:: 3.8 3.10
|
||||
The *loop* parameter.
|
||||
|
||||
The preferred way to use a Semaphore is an :keyword:`async with`
|
||||
statement::
|
||||
|
||||
|
@ -322,6 +337,9 @@ BoundedSemaphore
|
|||
increases the internal counter above the initial *value*.
|
||||
|
||||
|
||||
.. deprecated-removed:: 3.8 3.10
|
||||
The *loop* parameter.
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
|
|
@ -160,10 +160,13 @@ class Lock(_ContextManagerMixin):
|
|||
def __init__(self, *, loop=None):
|
||||
self._waiters = None
|
||||
self._locked = False
|
||||
if loop is not None:
|
||||
self._loop = loop
|
||||
else:
|
||||
if loop is None:
|
||||
self._loop = events.get_event_loop()
|
||||
else:
|
||||
self._loop = loop
|
||||
warnings.warn("The loop argument is deprecated since Python 3.8, "
|
||||
"and scheduled for removal in Python 3.10.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
def __repr__(self):
|
||||
res = super().__repr__()
|
||||
|
@ -253,10 +256,13 @@ class Event:
|
|||
def __init__(self, *, loop=None):
|
||||
self._waiters = collections.deque()
|
||||
self._value = False
|
||||
if loop is not None:
|
||||
self._loop = loop
|
||||
else:
|
||||
if loop is None:
|
||||
self._loop = events.get_event_loop()
|
||||
else:
|
||||
self._loop = loop
|
||||
warnings.warn("The loop argument is deprecated since Python 3.8, "
|
||||
"and scheduled for removal in Python 3.10.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
def __repr__(self):
|
||||
res = super().__repr__()
|
||||
|
@ -317,10 +323,13 @@ class Condition(_ContextManagerMixin):
|
|||
"""
|
||||
|
||||
def __init__(self, lock=None, *, loop=None):
|
||||
if loop is not None:
|
||||
self._loop = loop
|
||||
else:
|
||||
if loop is None:
|
||||
self._loop = events.get_event_loop()
|
||||
else:
|
||||
self._loop = loop
|
||||
warnings.warn("The loop argument is deprecated since Python 3.8, "
|
||||
"and scheduled for removal in Python 3.10.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
if lock is None:
|
||||
lock = Lock(loop=self._loop)
|
||||
|
@ -445,10 +454,13 @@ class Semaphore(_ContextManagerMixin):
|
|||
raise ValueError("Semaphore initial value must be >= 0")
|
||||
self._value = value
|
||||
self._waiters = collections.deque()
|
||||
if loop is not None:
|
||||
self._loop = loop
|
||||
else:
|
||||
if loop is None:
|
||||
self._loop = events.get_event_loop()
|
||||
else:
|
||||
self._loop = loop
|
||||
warnings.warn("The loop argument is deprecated since Python 3.8, "
|
||||
"and scheduled for removal in Python 3.10.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
def __repr__(self):
|
||||
res = super().__repr__()
|
||||
|
@ -508,6 +520,11 @@ class BoundedSemaphore(Semaphore):
|
|||
"""
|
||||
|
||||
def __init__(self, value=1, *, loop=None):
|
||||
if loop:
|
||||
warnings.warn("The loop argument is deprecated since Python 3.8, "
|
||||
"and scheduled for removal in Python 3.10.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
self._bound_value = value
|
||||
super().__init__(value, loop=loop)
|
||||
|
||||
|
|
|
@ -1718,6 +1718,7 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1738,6 +1739,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1759,6 +1762,7 @@ class SubprocessTestsMixin:
|
|||
self.check_killed(proto.returncode)
|
||||
|
||||
def test_subprocess_shell(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
connect = self.loop.subprocess_shell(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
'echo Python')
|
||||
|
@ -1778,6 +1782,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_shell(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
'exit 7', stdin=None, stdout=None, stderr=None)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.completed)
|
||||
|
@ -1788,6 +1794,7 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_shell(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
'exit 7', stdin=None, stdout=None, stderr=None)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.assertIsNone(transp.get_pipe_transport(0))
|
||||
|
@ -1803,6 +1810,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1818,6 +1827,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1839,6 +1850,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1856,6 +1869,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1876,6 +1891,8 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog, stderr=subprocess.STDOUT)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1899,6 +1916,7 @@ class SubprocessTestsMixin:
|
|||
connect = self.loop.subprocess_exec(
|
||||
functools.partial(MySubprocessProtocol, self.loop),
|
||||
sys.executable, prog)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
transp, proto = self.loop.run_until_complete(connect)
|
||||
self.assertIsInstance(proto, MySubprocessProtocol)
|
||||
self.loop.run_until_complete(proto.connected)
|
||||
|
@ -1938,7 +1956,6 @@ class SubprocessTestsMixin:
|
|||
self.assertEqual(7, proto.returncode)
|
||||
|
||||
def test_subprocess_exec_invalid_args(self):
|
||||
|
||||
async def connect(**kwds):
|
||||
await self.loop.subprocess_exec(
|
||||
asyncio.SubprocessProtocol,
|
||||
|
|
|
@ -28,9 +28,11 @@ class LockTests(test_utils.TestCase):
|
|||
|
||||
def test_ctor_loop(self):
|
||||
loop = mock.Mock()
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=loop)
|
||||
self.assertIs(lock._loop, loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
self.assertIs(lock._loop, self.loop)
|
||||
|
||||
|
@ -40,6 +42,7 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertIs(lock._loop, self.loop)
|
||||
|
||||
def test_repr(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
self.assertTrue(repr(lock).endswith('[unlocked]>'))
|
||||
self.assertTrue(RGX_REPR.match(repr(lock)))
|
||||
|
@ -55,9 +58,10 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertTrue(RGX_REPR.match(repr(lock)))
|
||||
|
||||
def test_lock(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
@ -74,6 +78,7 @@ class LockTests(test_utils.TestCase):
|
|||
def test_lock_by_with_statement(self):
|
||||
loop = asyncio.new_event_loop() # don't use TestLoop quirks
|
||||
self.set_event_loop(loop)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
primitives = [
|
||||
asyncio.Lock(loop=loop),
|
||||
asyncio.Condition(loop=loop),
|
||||
|
@ -81,7 +86,6 @@ class LockTests(test_utils.TestCase):
|
|||
asyncio.BoundedSemaphore(loop=loop),
|
||||
]
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def test(lock):
|
||||
yield from asyncio.sleep(0.01)
|
||||
|
@ -99,6 +103,7 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertFalse(primitive.locked())
|
||||
|
||||
def test_acquire(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
result = []
|
||||
|
||||
|
@ -150,6 +155,7 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertTrue(t3.result())
|
||||
|
||||
def test_acquire_cancel(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
self.assertTrue(self.loop.run_until_complete(lock.acquire()))
|
||||
|
||||
|
@ -175,6 +181,7 @@ class LockTests(test_utils.TestCase):
|
|||
# B's waiter; instead, it should move on to C's waiter.
|
||||
|
||||
# Setup: A has the lock, b and c are waiting.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
async def lockit(name, blocker):
|
||||
|
@ -211,6 +218,7 @@ class LockTests(test_utils.TestCase):
|
|||
# Issue 32734
|
||||
# Acquire 4 locks, cancel second, release first
|
||||
# and 2 locks are taken at once.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
lock_count = 0
|
||||
call_count = 0
|
||||
|
@ -256,6 +264,7 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertTrue(t3.cancelled())
|
||||
|
||||
def test_finished_waiter_cancelled(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
ta = asyncio.Task(lock.acquire(), loop=self.loop)
|
||||
|
@ -278,11 +287,13 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertTrue(tb.cancelled())
|
||||
|
||||
def test_release_not_acquired(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
self.assertRaises(RuntimeError, lock.release)
|
||||
|
||||
def test_release_no_waiters(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
self.loop.run_until_complete(lock.acquire())
|
||||
self.assertTrue(lock.locked())
|
||||
|
@ -291,9 +302,9 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertFalse(lock.locked())
|
||||
|
||||
def test_context_manager(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
@ -305,9 +316,9 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertFalse(lock.locked())
|
||||
|
||||
def test_context_manager_cant_reuse(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
@ -325,6 +336,7 @@ class LockTests(test_utils.TestCase):
|
|||
pass
|
||||
|
||||
def test_context_manager_no_yield(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
try:
|
||||
|
@ -346,9 +358,11 @@ class EventTests(test_utils.TestCase):
|
|||
|
||||
def test_ctor_loop(self):
|
||||
loop = mock.Mock()
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=loop)
|
||||
self.assertIs(ev._loop, loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
self.assertIs(ev._loop, self.loop)
|
||||
|
||||
|
@ -358,6 +372,7 @@ class EventTests(test_utils.TestCase):
|
|||
self.assertIs(ev._loop, self.loop)
|
||||
|
||||
def test_repr(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
self.assertTrue(repr(ev).endswith('[unset]>'))
|
||||
match = RGX_REPR.match(repr(ev))
|
||||
|
@ -372,6 +387,7 @@ class EventTests(test_utils.TestCase):
|
|||
self.assertTrue(RGX_REPR.match(repr(ev)))
|
||||
|
||||
def test_wait(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
self.assertFalse(ev.is_set())
|
||||
|
||||
|
@ -409,6 +425,7 @@ class EventTests(test_utils.TestCase):
|
|||
self.assertIsNone(t3.result())
|
||||
|
||||
def test_wait_on_set(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
ev.set()
|
||||
|
||||
|
@ -416,6 +433,7 @@ class EventTests(test_utils.TestCase):
|
|||
self.assertTrue(res)
|
||||
|
||||
def test_wait_cancel(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
|
||||
wait = asyncio.Task(ev.wait(), loop=self.loop)
|
||||
|
@ -426,6 +444,7 @@ class EventTests(test_utils.TestCase):
|
|||
self.assertFalse(ev._waiters)
|
||||
|
||||
def test_clear(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
self.assertFalse(ev.is_set())
|
||||
|
||||
|
@ -436,6 +455,7 @@ class EventTests(test_utils.TestCase):
|
|||
self.assertFalse(ev.is_set())
|
||||
|
||||
def test_clear_with_waiters(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
ev = asyncio.Event(loop=self.loop)
|
||||
result = []
|
||||
|
||||
|
@ -472,6 +492,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
|
||||
def test_ctor_loop(self):
|
||||
loop = mock.Mock()
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=loop)
|
||||
self.assertIs(cond._loop, loop)
|
||||
|
||||
|
@ -479,11 +500,13 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertIs(cond._loop, self.loop)
|
||||
|
||||
def test_ctor_noloop(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
asyncio.set_event_loop(self.loop)
|
||||
cond = asyncio.Condition()
|
||||
self.assertIs(cond._loop, self.loop)
|
||||
|
||||
def test_wait(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
result = []
|
||||
|
||||
|
@ -547,6 +570,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(t3.result())
|
||||
|
||||
def test_wait_cancel(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
self.loop.run_until_complete(cond.acquire())
|
||||
|
||||
|
@ -559,6 +583,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(cond.locked())
|
||||
|
||||
def test_wait_cancel_contested(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
|
||||
self.loop.run_until_complete(cond.acquire())
|
||||
|
@ -585,6 +610,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
|
||||
def test_wait_cancel_after_notify(self):
|
||||
# See bpo-32841
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
waited = False
|
||||
|
||||
|
@ -609,12 +635,14 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(waited)
|
||||
|
||||
def test_wait_unacquired(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
self.assertRaises(
|
||||
RuntimeError,
|
||||
self.loop.run_until_complete, cond.wait())
|
||||
|
||||
def test_wait_for(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
presult = False
|
||||
|
||||
|
@ -652,6 +680,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(t.result())
|
||||
|
||||
def test_wait_for_unacquired(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
|
||||
# predicate can return true immediately
|
||||
|
@ -664,6 +693,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
cond.wait_for(lambda: False))
|
||||
|
||||
def test_notify(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
result = []
|
||||
|
||||
|
@ -716,6 +746,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(t3.result())
|
||||
|
||||
def test_notify_all(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
|
||||
result = []
|
||||
|
@ -752,14 +783,17 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(t2.result())
|
||||
|
||||
def test_notify_unacquired(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
self.assertRaises(RuntimeError, cond.notify)
|
||||
|
||||
def test_notify_all_unacquired(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
self.assertRaises(RuntimeError, cond.notify_all)
|
||||
|
||||
def test_repr(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
self.assertTrue('unlocked' in repr(cond))
|
||||
self.assertTrue(RGX_REPR.match(repr(cond)))
|
||||
|
@ -776,6 +810,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertTrue(RGX_REPR.match(repr(cond)))
|
||||
|
||||
def test_context_manager(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
@ -790,6 +825,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertFalse(cond.locked())
|
||||
|
||||
def test_context_manager_no_yield(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
|
||||
try:
|
||||
|
@ -803,6 +839,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
self.assertFalse(cond.locked())
|
||||
|
||||
def test_explicit_lock(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
cond = asyncio.Condition(lock, loop=self.loop)
|
||||
|
||||
|
@ -812,7 +849,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
def test_ambiguous_loops(self):
|
||||
loop = self.new_test_loop()
|
||||
self.addCleanup(loop.close)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
with self.assertRaises(ValueError):
|
||||
asyncio.Condition(lock, loop=loop)
|
||||
|
@ -827,6 +864,7 @@ class ConditionTests(test_utils.TestCase):
|
|||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(condition.wait(), timeout=0.5)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
loop.run_until_complete(task_timeout())
|
||||
|
||||
|
||||
|
@ -838,9 +876,11 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
|
||||
def test_ctor_loop(self):
|
||||
loop = mock.Mock()
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(loop=loop)
|
||||
self.assertIs(sem._loop, loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(loop=self.loop)
|
||||
self.assertIs(sem._loop, self.loop)
|
||||
|
||||
|
@ -850,10 +890,12 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.assertIs(sem._loop, self.loop)
|
||||
|
||||
def test_initial_value_zero(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(0, loop=self.loop)
|
||||
self.assertTrue(sem.locked())
|
||||
|
||||
def test_repr(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(loop=self.loop)
|
||||
self.assertTrue(repr(sem).endswith('[unlocked, value:1]>'))
|
||||
self.assertTrue(RGX_REPR.match(repr(sem)))
|
||||
|
@ -872,6 +914,7 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.assertTrue(RGX_REPR.match(repr(sem)))
|
||||
|
||||
def test_semaphore(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(loop=self.loop)
|
||||
self.assertEqual(1, sem._value)
|
||||
|
||||
|
@ -895,6 +938,7 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.assertRaises(ValueError, asyncio.Semaphore, -1)
|
||||
|
||||
def test_acquire(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(3, loop=self.loop)
|
||||
result = []
|
||||
|
||||
|
@ -956,6 +1000,7 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.loop.run_until_complete(asyncio.gather(*race_tasks))
|
||||
|
||||
def test_acquire_cancel(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(loop=self.loop)
|
||||
self.loop.run_until_complete(sem.acquire())
|
||||
|
||||
|
@ -968,6 +1013,7 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
all(waiter.done() for waiter in sem._waiters))
|
||||
|
||||
def test_acquire_cancel_before_awoken(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(value=0, loop=self.loop)
|
||||
|
||||
t1 = asyncio.Task(sem.acquire(), loop=self.loop)
|
||||
|
@ -990,6 +1036,7 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
test_utils.run_briefly(self.loop)
|
||||
|
||||
def test_acquire_hang(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(value=0, loop=self.loop)
|
||||
|
||||
t1 = asyncio.Task(sem.acquire(), loop=self.loop)
|
||||
|
@ -1004,11 +1051,13 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.assertTrue(sem.locked())
|
||||
|
||||
def test_release_not_acquired(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.BoundedSemaphore(loop=self.loop)
|
||||
|
||||
self.assertRaises(ValueError, sem.release)
|
||||
|
||||
def test_release_no_waiters(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(loop=self.loop)
|
||||
self.loop.run_until_complete(sem.acquire())
|
||||
self.assertTrue(sem.locked())
|
||||
|
@ -1017,9 +1066,9 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.assertFalse(sem.locked())
|
||||
|
||||
def test_context_manager(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(2, loop=self.loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
@ -1035,6 +1084,7 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
self.assertEqual(2, sem._value)
|
||||
|
||||
def test_context_manager_no_yield(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
sem = asyncio.Semaphore(2, loop=self.loop)
|
||||
|
||||
try:
|
||||
|
|
|
@ -43,6 +43,7 @@ class BaseTest(test_utils.TestCase):
|
|||
class LockTests(BaseTest):
|
||||
|
||||
def test_context_manager_async_with(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
primitives = [
|
||||
asyncio.Lock(loop=self.loop),
|
||||
asyncio.Condition(loop=self.loop),
|
||||
|
@ -65,6 +66,7 @@ class LockTests(BaseTest):
|
|||
self.assertFalse(primitive.locked())
|
||||
|
||||
def test_context_manager_with_await(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
primitives = [
|
||||
asyncio.Lock(loop=self.loop),
|
||||
asyncio.Condition(loop=self.loop),
|
||||
|
|
|
@ -35,6 +35,7 @@ class QueueBasicTests(_QueueTestBase):
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=loop)
|
||||
self.assertTrue(fn(q).startswith('<Queue'), fn(q))
|
||||
id_is_present = hex(id(q)) in fn(q)
|
||||
|
@ -50,6 +51,7 @@ class QueueBasicTests(_QueueTestBase):
|
|||
# resume q.get coroutine to finish generator
|
||||
q.put_nowait(0)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
loop.run_until_complete(add_getter())
|
||||
|
||||
async def add_putter():
|
||||
|
@ -63,22 +65,25 @@ class QueueBasicTests(_QueueTestBase):
|
|||
# resume q.put coroutine to finish generator
|
||||
q.get_nowait()
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
loop.run_until_complete(add_putter())
|
||||
|
||||
q = asyncio.Queue(loop=loop)
|
||||
q.put_nowait(1)
|
||||
self.assertTrue('_queue=[1]' in fn(q))
|
||||
|
||||
def test_ctor_loop(self):
|
||||
loop = mock.Mock()
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=loop)
|
||||
self.assertIs(q._loop, loop)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
self.assertIs(q._loop, self.loop)
|
||||
|
||||
def test_ctor_noloop(self):
|
||||
asyncio.set_event_loop(self.loop)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue()
|
||||
self.assertIs(q._loop, self.loop)
|
||||
|
||||
|
@ -89,6 +94,7 @@ class QueueBasicTests(_QueueTestBase):
|
|||
self._test_repr_or_str(str, False)
|
||||
|
||||
def test_empty(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
self.assertTrue(q.empty())
|
||||
q.put_nowait(1)
|
||||
|
@ -97,14 +103,17 @@ class QueueBasicTests(_QueueTestBase):
|
|||
self.assertTrue(q.empty())
|
||||
|
||||
def test_full(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
self.assertFalse(q.full())
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(maxsize=1, loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
self.assertTrue(q.full())
|
||||
|
||||
def test_order(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
for i in [1, 3, 2]:
|
||||
q.put_nowait(i)
|
||||
|
@ -123,6 +132,7 @@ class QueueBasicTests(_QueueTestBase):
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(maxsize=2, loop=loop)
|
||||
self.assertEqual(2, q.maxsize)
|
||||
have_been_put = []
|
||||
|
@ -157,6 +167,7 @@ class QueueBasicTests(_QueueTestBase):
|
|||
class QueueGetTests(_QueueTestBase):
|
||||
|
||||
def test_blocking_get(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
|
||||
|
@ -167,6 +178,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
self.assertEqual(1, res)
|
||||
|
||||
def test_get_with_putters(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(1, loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
|
||||
|
@ -187,6 +199,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=loop)
|
||||
started = asyncio.Event(loop=loop)
|
||||
finished = False
|
||||
|
@ -212,11 +225,13 @@ class QueueGetTests(_QueueTestBase):
|
|||
self.assertAlmostEqual(0.01, loop.time())
|
||||
|
||||
def test_nonblocking_get(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
self.assertEqual(1, q.get_nowait())
|
||||
|
||||
def test_nonblocking_get_exception(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
self.assertRaises(asyncio.QueueEmpty, q.get_nowait)
|
||||
|
||||
|
@ -231,6 +246,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=loop)
|
||||
|
||||
async def queue_get():
|
||||
|
@ -246,6 +262,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
self.assertAlmostEqual(0.06, loop.time())
|
||||
|
||||
def test_get_cancelled_race(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
|
||||
t1 = asyncio.Task(q.get(), loop=self.loop)
|
||||
|
@ -260,6 +277,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
self.assertEqual(t2.result(), 'a')
|
||||
|
||||
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)
|
||||
|
@ -280,6 +298,8 @@ class QueueGetTests(_QueueTestBase):
|
|||
|
||||
queue_size = 1
|
||||
producer_num_items = 5
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(queue_size, loop=self.loop)
|
||||
|
||||
self.loop.run_until_complete(
|
||||
|
@ -301,6 +321,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
except asyncio.TimeoutError:
|
||||
pass
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
queue = asyncio.Queue(loop=self.loop, maxsize=5)
|
||||
self.loop.run_until_complete(self.loop.create_task(consumer(queue)))
|
||||
self.assertEqual(len(queue._getters), 0)
|
||||
|
@ -309,6 +330,7 @@ class QueueGetTests(_QueueTestBase):
|
|||
class QueuePutTests(_QueueTestBase):
|
||||
|
||||
def test_blocking_put(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
|
||||
async def queue_put():
|
||||
|
@ -326,6 +348,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(maxsize=1, loop=loop)
|
||||
started = asyncio.Event(loop=loop)
|
||||
finished = False
|
||||
|
@ -349,6 +372,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
self.assertAlmostEqual(0.01, loop.time())
|
||||
|
||||
def test_nonblocking_put(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
self.assertEqual(1, q.get_nowait())
|
||||
|
@ -360,6 +384,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=loop)
|
||||
|
||||
reader = loop.create_task(q.get())
|
||||
|
@ -389,6 +414,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
loop = self.new_test_loop(gen)
|
||||
loop.set_debug(True)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=loop)
|
||||
|
||||
reader1 = loop.create_task(q.get())
|
||||
|
@ -418,6 +444,8 @@ class QueuePutTests(_QueueTestBase):
|
|||
yield 0.1
|
||||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(1, loop=loop)
|
||||
|
||||
q.put_nowait(1)
|
||||
|
@ -442,17 +470,20 @@ class QueuePutTests(_QueueTestBase):
|
|||
self.assertEqual(q.qsize(), 0)
|
||||
|
||||
def test_nonblocking_put_exception(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(maxsize=1, loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
self.assertRaises(asyncio.QueueFull, q.put_nowait, 2)
|
||||
|
||||
def test_float_maxsize(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(maxsize=1.3, loop=self.loop)
|
||||
q.put_nowait(1)
|
||||
q.put_nowait(2)
|
||||
self.assertTrue(q.full())
|
||||
self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(maxsize=1.3, loop=self.loop)
|
||||
|
||||
async def queue_put():
|
||||
|
@ -462,6 +493,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
self.loop.run_until_complete(queue_put())
|
||||
|
||||
def test_put_cancelled(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop)
|
||||
|
||||
async def queue_put():
|
||||
|
@ -477,6 +509,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
self.assertTrue(t.result())
|
||||
|
||||
def test_put_cancelled_race(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.Queue(loop=self.loop, maxsize=1)
|
||||
|
||||
put_a = asyncio.Task(q.put('a'), loop=self.loop)
|
||||
|
@ -497,6 +530,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
self.loop.run_until_complete(put_b)
|
||||
|
||||
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)
|
||||
test_utils.run_briefly(self.loop)
|
||||
|
@ -506,6 +540,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
def test_why_are_putters_waiting(self):
|
||||
# From issue #265.
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
queue = asyncio.Queue(2, loop=self.loop)
|
||||
|
||||
async def putter(item):
|
||||
|
@ -532,6 +567,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
loop = self.new_test_loop(a_generator)
|
||||
|
||||
# Full queue.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
queue = asyncio.Queue(loop=loop, maxsize=1)
|
||||
queue.put_nowait(1)
|
||||
|
||||
|
@ -555,6 +591,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
loop = self.new_test_loop(gen)
|
||||
|
||||
# Full Queue.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
queue = asyncio.Queue(1, loop=loop)
|
||||
queue.put_nowait(1)
|
||||
|
||||
|
@ -578,6 +615,7 @@ class QueuePutTests(_QueueTestBase):
|
|||
class LifoQueueTests(_QueueTestBase):
|
||||
|
||||
def test_order(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.LifoQueue(loop=self.loop)
|
||||
for i in [1, 3, 2]:
|
||||
q.put_nowait(i)
|
||||
|
@ -589,6 +627,7 @@ class LifoQueueTests(_QueueTestBase):
|
|||
class PriorityQueueTests(_QueueTestBase):
|
||||
|
||||
def test_order(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = asyncio.PriorityQueue(loop=self.loop)
|
||||
for i in [1, 3, 2]:
|
||||
q.put_nowait(i)
|
||||
|
@ -602,10 +641,12 @@ class _QueueJoinTestMixin:
|
|||
q_class = None
|
||||
|
||||
def test_task_done_underflow(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = self.q_class(loop=self.loop)
|
||||
self.assertRaises(ValueError, q.task_done)
|
||||
|
||||
def test_task_done(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = self.q_class(loop=self.loop)
|
||||
for i in range(100):
|
||||
q.put_nowait(i)
|
||||
|
@ -641,6 +682,7 @@ class _QueueJoinTestMixin:
|
|||
self.loop.run_until_complete(asyncio.wait(tasks))
|
||||
|
||||
def test_join_empty_queue(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = self.q_class(loop=self.loop)
|
||||
|
||||
# Test that a queue join()s successfully, and before anything else
|
||||
|
@ -653,6 +695,7 @@ class _QueueJoinTestMixin:
|
|||
self.loop.run_until_complete(join())
|
||||
|
||||
def test_format(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
q = self.q_class(loop=self.loop)
|
||||
self.assertEqual(q._format(), 'maxsize=0')
|
||||
|
||||
|
|
|
@ -1231,7 +1231,7 @@ class BaseTaskTests:
|
|||
for f in asyncio.as_completed([b, c, a], loop=loop):
|
||||
values.append(await f)
|
||||
return values
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
res = loop.run_until_complete(self.new_task(loop, foo()))
|
||||
self.assertAlmostEqual(0.15, loop.time())
|
||||
self.assertTrue('a' in res[:2])
|
||||
|
@ -1239,6 +1239,7 @@ class BaseTaskTests:
|
|||
self.assertEqual(res[2], 'c')
|
||||
|
||||
# Doing it again should take no time and exercise a different path.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
res = loop.run_until_complete(self.new_task(loop, foo()))
|
||||
self.assertAlmostEqual(0.15, loop.time())
|
||||
|
||||
|
@ -1267,6 +1268,7 @@ class BaseTaskTests:
|
|||
values.append((2, exc))
|
||||
return values
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
res = loop.run_until_complete(self.new_task(loop, foo()))
|
||||
self.assertEqual(len(res), 2, res)
|
||||
self.assertEqual(res[0], (1, 'a'))
|
||||
|
@ -1294,6 +1296,7 @@ class BaseTaskTests:
|
|||
v = await f
|
||||
self.assertEqual(v, 'a')
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
loop.run_until_complete(self.new_task(loop, foo()))
|
||||
|
||||
def test_as_completed_reverse_wait(self):
|
||||
|
@ -1308,6 +1311,8 @@ class BaseTaskTests:
|
|||
a = asyncio.sleep(0.05, 'a')
|
||||
b = asyncio.sleep(0.10, 'b')
|
||||
fs = {a, b}
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
futs = list(asyncio.as_completed(fs, loop=loop))
|
||||
self.assertEqual(len(futs), 2)
|
||||
|
||||
|
@ -1333,6 +1338,7 @@ class BaseTaskTests:
|
|||
a = asyncio.sleep(0.05, 'a')
|
||||
b = asyncio.sleep(0.05, 'b')
|
||||
fs = {a, b}
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
futs = list(asyncio.as_completed(fs, loop=loop))
|
||||
self.assertEqual(len(futs), 2)
|
||||
waiter = asyncio.wait(futs)
|
||||
|
@ -1356,6 +1362,7 @@ class BaseTaskTests:
|
|||
result.append((yield from f))
|
||||
return result
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
fut = self.new_task(self.loop, runner())
|
||||
self.loop.run_until_complete(fut)
|
||||
result = fut.result()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue