Commit 537877d8 authored by Emmanuel Arias's avatar Emmanuel Arias Committed by Miss Islington (bot)

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
parent 9669931e
...@@ -59,6 +59,9 @@ Lock ...@@ -59,6 +59,9 @@ Lock
finally: finally:
lock.release() lock.release()
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
.. coroutinemethod:: acquire() .. coroutinemethod:: acquire()
Acquire the lock. Acquire the lock.
...@@ -101,6 +104,10 @@ Event ...@@ -101,6 +104,10 @@ Event
:meth:`clear` method. The :meth:`wait` method blocks until the :meth:`clear` method. The :meth:`wait` method blocks until the
flag is set to *true*. The flag is set to *false* initially. 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: .. _asyncio_example_sync_event:
Example:: Example::
...@@ -173,6 +180,10 @@ Condition ...@@ -173,6 +180,10 @@ Condition
``None``. In the latter case a new Lock object is created ``None``. In the latter case a new Lock object is created
automatically. automatically.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
The preferred way to use a Condition is an :keyword:`async with` The preferred way to use a Condition is an :keyword:`async with`
statement:: statement::
...@@ -269,6 +280,10 @@ Semaphore ...@@ -269,6 +280,10 @@ Semaphore
internal counter (``1`` by default). If the given value is internal counter (``1`` by default). If the given value is
less than ``0`` a :exc:`ValueError` is raised. 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` The preferred way to use a Semaphore is an :keyword:`async with`
statement:: statement::
...@@ -322,6 +337,9 @@ BoundedSemaphore ...@@ -322,6 +337,9 @@ BoundedSemaphore
increases the internal counter above the initial *value*. increases the internal counter above the initial *value*.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
--------- ---------
......
...@@ -160,10 +160,13 @@ class Lock(_ContextManagerMixin): ...@@ -160,10 +160,13 @@ class Lock(_ContextManagerMixin):
def __init__(self, *, loop=None): def __init__(self, *, loop=None):
self._waiters = None self._waiters = None
self._locked = False self._locked = False
if loop is not None: if loop is None:
self._loop = loop
else:
self._loop = events.get_event_loop() 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): def __repr__(self):
res = super().__repr__() res = super().__repr__()
...@@ -253,10 +256,13 @@ class Event: ...@@ -253,10 +256,13 @@ class Event:
def __init__(self, *, loop=None): def __init__(self, *, loop=None):
self._waiters = collections.deque() self._waiters = collections.deque()
self._value = False self._value = False
if loop is not None: if loop is None:
self._loop = loop
else:
self._loop = events.get_event_loop() 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): def __repr__(self):
res = super().__repr__() res = super().__repr__()
...@@ -317,10 +323,13 @@ class Condition(_ContextManagerMixin): ...@@ -317,10 +323,13 @@ class Condition(_ContextManagerMixin):
""" """
def __init__(self, lock=None, *, loop=None): def __init__(self, lock=None, *, loop=None):
if loop is not None: if loop is None:
self._loop = loop
else:
self._loop = events.get_event_loop() 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: if lock is None:
lock = Lock(loop=self._loop) lock = Lock(loop=self._loop)
...@@ -445,10 +454,13 @@ class Semaphore(_ContextManagerMixin): ...@@ -445,10 +454,13 @@ class Semaphore(_ContextManagerMixin):
raise ValueError("Semaphore initial value must be >= 0") raise ValueError("Semaphore initial value must be >= 0")
self._value = value self._value = value
self._waiters = collections.deque() self._waiters = collections.deque()
if loop is not None: if loop is None:
self._loop = loop
else:
self._loop = events.get_event_loop() 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): def __repr__(self):
res = super().__repr__() res = super().__repr__()
...@@ -508,6 +520,11 @@ class BoundedSemaphore(Semaphore): ...@@ -508,6 +520,11 @@ class BoundedSemaphore(Semaphore):
""" """
def __init__(self, value=1, *, loop=None): 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 self._bound_value = value
super().__init__(value, loop=loop) super().__init__(value, loop=loop)
......
...@@ -1719,19 +1719,20 @@ class SubprocessTestsMixin: ...@@ -1719,19 +1719,20 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect) with self.assertWarns(DeprecationWarning):
self.assertIsInstance(proto, MySubprocessProtocol) transp, proto = self.loop.run_until_complete(connect)
self.loop.run_until_complete(proto.connected) self.assertIsInstance(proto, MySubprocessProtocol)
self.assertEqual('CONNECTED', proto.state) self.loop.run_until_complete(proto.connected)
self.assertEqual('CONNECTED', proto.state)
stdin = transp.get_pipe_transport(0) stdin = transp.get_pipe_transport(0)
stdin.write(b'Python The Winner') stdin.write(b'Python The Winner')
self.loop.run_until_complete(proto.got_data[1].wait()) self.loop.run_until_complete(proto.got_data[1].wait())
with test_utils.disable_logger(): with test_utils.disable_logger():
transp.close() transp.close()
self.loop.run_until_complete(proto.completed) self.loop.run_until_complete(proto.completed)
self.check_killed(proto.returncode) self.check_killed(proto.returncode)
self.assertEqual(b'Python The Winner', proto.data[1]) self.assertEqual(b'Python The Winner', proto.data[1])
def test_subprocess_interactive(self): def test_subprocess_interactive(self):
prog = os.path.join(os.path.dirname(__file__), 'echo.py') prog = os.path.join(os.path.dirname(__file__), 'echo.py')
...@@ -1739,47 +1740,52 @@ class SubprocessTestsMixin: ...@@ -1739,47 +1740,52 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
self.assertEqual('CONNECTED', proto.state)
stdin = transp.get_pipe_transport(0) with self.assertWarns(DeprecationWarning):
stdin.write(b'Python ') transp, proto = self.loop.run_until_complete(connect)
self.loop.run_until_complete(proto.got_data[1].wait()) self.assertIsInstance(proto, MySubprocessProtocol)
proto.got_data[1].clear() self.loop.run_until_complete(proto.connected)
self.assertEqual(b'Python ', proto.data[1]) self.assertEqual('CONNECTED', proto.state)
stdin.write(b'The Winner') stdin = transp.get_pipe_transport(0)
self.loop.run_until_complete(proto.got_data[1].wait()) stdin.write(b'Python ')
self.assertEqual(b'Python The Winner', proto.data[1]) self.loop.run_until_complete(proto.got_data[1].wait())
proto.got_data[1].clear()
self.assertEqual(b'Python ', proto.data[1])
with test_utils.disable_logger(): stdin.write(b'The Winner')
transp.close() self.loop.run_until_complete(proto.got_data[1].wait())
self.loop.run_until_complete(proto.completed) self.assertEqual(b'Python The Winner', proto.data[1])
self.check_killed(proto.returncode)
with test_utils.disable_logger():
transp.close()
self.loop.run_until_complete(proto.completed)
self.check_killed(proto.returncode)
def test_subprocess_shell(self): def test_subprocess_shell(self):
connect = self.loop.subprocess_shell( with self.assertWarns(DeprecationWarning):
functools.partial(MySubprocessProtocol, self.loop), connect = self.loop.subprocess_shell(
'echo Python') functools.partial(MySubprocessProtocol, self.loop),
transp, proto = self.loop.run_until_complete(connect) 'echo Python')
self.assertIsInstance(proto, MySubprocessProtocol) transp, proto = self.loop.run_until_complete(connect)
self.loop.run_until_complete(proto.connected) self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
transp.get_pipe_transport(0).close() transp.get_pipe_transport(0).close()
self.loop.run_until_complete(proto.completed) self.loop.run_until_complete(proto.completed)
self.assertEqual(0, proto.returncode) self.assertEqual(0, proto.returncode)
self.assertTrue(all(f.done() for f in proto.disconnects.values())) self.assertTrue(all(f.done() for f in proto.disconnects.values()))
self.assertEqual(proto.data[1].rstrip(b'\r\n'), b'Python') self.assertEqual(proto.data[1].rstrip(b'\r\n'), b'Python')
self.assertEqual(proto.data[2], b'') self.assertEqual(proto.data[2], b'')
transp.close() transp.close()
def test_subprocess_exitcode(self): def test_subprocess_exitcode(self):
connect = self.loop.subprocess_shell( connect = self.loop.subprocess_shell(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
'exit 7', stdin=None, stdout=None, stderr=None) 'exit 7', stdin=None, stdout=None, stderr=None)
transp, proto = self.loop.run_until_complete(connect)
with self.assertWarns(DeprecationWarning):
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol) self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.completed) self.loop.run_until_complete(proto.completed)
self.assertEqual(7, proto.returncode) self.assertEqual(7, proto.returncode)
...@@ -1789,7 +1795,8 @@ class SubprocessTestsMixin: ...@@ -1789,7 +1795,8 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_shell( connect = self.loop.subprocess_shell(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
'exit 7', stdin=None, stdout=None, stderr=None) 'exit 7', stdin=None, stdout=None, stderr=None)
transp, proto = self.loop.run_until_complete(connect) with self.assertWarns(DeprecationWarning):
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol) self.assertIsInstance(proto, MySubprocessProtocol)
self.assertIsNone(transp.get_pipe_transport(0)) self.assertIsNone(transp.get_pipe_transport(0))
self.assertIsNone(transp.get_pipe_transport(1)) self.assertIsNone(transp.get_pipe_transport(1))
...@@ -1804,14 +1811,16 @@ class SubprocessTestsMixin: ...@@ -1804,14 +1811,16 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
transp.kill() with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(proto.completed) transp, proto = self.loop.run_until_complete(connect)
self.check_killed(proto.returncode) self.assertIsInstance(proto, MySubprocessProtocol)
transp.close() self.loop.run_until_complete(proto.connected)
transp.kill()
self.loop.run_until_complete(proto.completed)
self.check_killed(proto.returncode)
transp.close()
def test_subprocess_terminate(self): def test_subprocess_terminate(self):
prog = os.path.join(os.path.dirname(__file__), 'echo.py') prog = os.path.join(os.path.dirname(__file__), 'echo.py')
...@@ -1819,14 +1828,16 @@ class SubprocessTestsMixin: ...@@ -1819,14 +1828,16 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
transp.terminate() with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(proto.completed) transp, proto = self.loop.run_until_complete(connect)
self.check_terminated(proto.returncode) self.assertIsInstance(proto, MySubprocessProtocol)
transp.close() self.loop.run_until_complete(proto.connected)
transp.terminate()
self.loop.run_until_complete(proto.completed)
self.check_terminated(proto.returncode)
transp.close()
@unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP") @unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
def test_subprocess_send_signal(self): def test_subprocess_send_signal(self):
...@@ -1840,14 +1851,16 @@ class SubprocessTestsMixin: ...@@ -1840,14 +1851,16 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
transp.send_signal(signal.SIGHUP) with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(proto.completed) transp, proto = self.loop.run_until_complete(connect)
self.assertEqual(-signal.SIGHUP, proto.returncode) self.assertIsInstance(proto, MySubprocessProtocol)
transp.close() self.loop.run_until_complete(proto.connected)
transp.send_signal(signal.SIGHUP)
self.loop.run_until_complete(proto.completed)
self.assertEqual(-signal.SIGHUP, proto.returncode)
transp.close()
finally: finally:
signal.signal(signal.SIGHUP, old_handler) signal.signal(signal.SIGHUP, old_handler)
...@@ -1857,19 +1870,21 @@ class SubprocessTestsMixin: ...@@ -1857,19 +1870,21 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
stdin = transp.get_pipe_transport(0) with self.assertWarns(DeprecationWarning):
stdin.write(b'test') transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
self.loop.run_until_complete(proto.completed) stdin = transp.get_pipe_transport(0)
stdin.write(b'test')
transp.close() self.loop.run_until_complete(proto.completed)
self.assertEqual(b'OUT:test', proto.data[1])
self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2]) transp.close()
self.assertEqual(0, proto.returncode) self.assertEqual(b'OUT:test', proto.data[1])
self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2])
self.assertEqual(0, proto.returncode)
def test_subprocess_stderr_redirect_to_stdout(self): def test_subprocess_stderr_redirect_to_stdout(self):
prog = os.path.join(os.path.dirname(__file__), 'echo2.py') prog = os.path.join(os.path.dirname(__file__), 'echo2.py')
...@@ -1877,22 +1892,24 @@ class SubprocessTestsMixin: ...@@ -1877,22 +1892,24 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog, stderr=subprocess.STDOUT) sys.executable, prog, stderr=subprocess.STDOUT)
transp, proto = self.loop.run_until_complete(connect)
self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
stdin = transp.get_pipe_transport(0) with self.assertWarns(DeprecationWarning):
self.assertIsNotNone(transp.get_pipe_transport(1)) transp, proto = self.loop.run_until_complete(connect)
self.assertIsNone(transp.get_pipe_transport(2)) self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
stdin.write(b'test') stdin = transp.get_pipe_transport(0)
self.loop.run_until_complete(proto.completed) self.assertIsNotNone(transp.get_pipe_transport(1))
self.assertTrue(proto.data[1].startswith(b'OUT:testERR:test'), self.assertIsNone(transp.get_pipe_transport(2))
proto.data[1])
self.assertEqual(b'', proto.data[2])
transp.close() stdin.write(b'test')
self.assertEqual(0, proto.returncode) self.loop.run_until_complete(proto.completed)
self.assertTrue(proto.data[1].startswith(b'OUT:testERR:test'),
proto.data[1])
self.assertEqual(b'', proto.data[2])
transp.close()
self.assertEqual(0, proto.returncode)
def test_subprocess_close_client_stream(self): def test_subprocess_close_client_stream(self):
prog = os.path.join(os.path.dirname(__file__), 'echo3.py') prog = os.path.join(os.path.dirname(__file__), 'echo3.py')
...@@ -1900,32 +1917,33 @@ class SubprocessTestsMixin: ...@@ -1900,32 +1917,33 @@ class SubprocessTestsMixin:
connect = self.loop.subprocess_exec( connect = self.loop.subprocess_exec(
functools.partial(MySubprocessProtocol, self.loop), functools.partial(MySubprocessProtocol, self.loop),
sys.executable, prog) sys.executable, prog)
transp, proto = self.loop.run_until_complete(connect) with self.assertWarns(DeprecationWarning):
self.assertIsInstance(proto, MySubprocessProtocol) transp, proto = self.loop.run_until_complete(connect)
self.loop.run_until_complete(proto.connected) self.assertIsInstance(proto, MySubprocessProtocol)
self.loop.run_until_complete(proto.connected)
stdin = transp.get_pipe_transport(0) stdin = transp.get_pipe_transport(0)
stdout = transp.get_pipe_transport(1) stdout = transp.get_pipe_transport(1)
stdin.write(b'test') stdin.write(b'test')
self.loop.run_until_complete(proto.got_data[1].wait()) self.loop.run_until_complete(proto.got_data[1].wait())
self.assertEqual(b'OUT:test', proto.data[1]) self.assertEqual(b'OUT:test', proto.data[1])
stdout.close() stdout.close()
self.loop.run_until_complete(proto.disconnects[1]) self.loop.run_until_complete(proto.disconnects[1])
stdin.write(b'xxx') stdin.write(b'xxx')
self.loop.run_until_complete(proto.got_data[2].wait()) self.loop.run_until_complete(proto.got_data[2].wait())
if sys.platform != 'win32': if sys.platform != 'win32':
self.assertEqual(b'ERR:BrokenPipeError', proto.data[2]) self.assertEqual(b'ERR:BrokenPipeError', proto.data[2])
else: else:
# After closing the read-end of a pipe, writing to the # After closing the read-end of a pipe, writing to the
# write-end using os.write() fails with errno==EINVAL and # write-end using os.write() fails with errno==EINVAL and
# GetLastError()==ERROR_INVALID_NAME on Windows!?! (Using # GetLastError()==ERROR_INVALID_NAME on Windows!?! (Using
# WriteFile() we get ERROR_BROKEN_PIPE as expected.) # WriteFile() we get ERROR_BROKEN_PIPE as expected.)
self.assertEqual(b'ERR:OSError', proto.data[2]) self.assertEqual(b'ERR:OSError', proto.data[2])
with test_utils.disable_logger(): with test_utils.disable_logger():
transp.close() transp.close()
self.loop.run_until_complete(proto.completed) self.loop.run_until_complete(proto.completed)
self.check_killed(proto.returncode) self.check_killed(proto.returncode)
def test_subprocess_wait_no_same_group(self): def test_subprocess_wait_no_same_group(self):
# start the new process in a new session # start the new process in a new session
...@@ -1939,7 +1957,6 @@ class SubprocessTestsMixin: ...@@ -1939,7 +1957,6 @@ class SubprocessTestsMixin:
self.assertEqual(7, proto.returncode) self.assertEqual(7, proto.returncode)
def test_subprocess_exec_invalid_args(self): def test_subprocess_exec_invalid_args(self):
async def connect(**kwds): async def connect(**kwds):
await self.loop.subprocess_exec( await self.loop.subprocess_exec(
asyncio.SubprocessProtocol, asyncio.SubprocessProtocol,
......
...@@ -28,10 +28,12 @@ class LockTests(test_utils.TestCase): ...@@ -28,10 +28,12 @@ class LockTests(test_utils.TestCase):
def test_ctor_loop(self): def test_ctor_loop(self):
loop = mock.Mock() loop = mock.Mock()
lock = asyncio.Lock(loop=loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=loop)
self.assertIs(lock._loop, loop) self.assertIs(lock._loop, loop)
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
self.assertIs(lock._loop, self.loop) self.assertIs(lock._loop, self.loop)
def test_ctor_noloop(self): def test_ctor_noloop(self):
...@@ -40,7 +42,8 @@ class LockTests(test_utils.TestCase): ...@@ -40,7 +42,8 @@ class LockTests(test_utils.TestCase):
self.assertIs(lock._loop, self.loop) self.assertIs(lock._loop, self.loop)
def test_repr(self): def test_repr(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
self.assertTrue(repr(lock).endswith('[unlocked]>')) self.assertTrue(repr(lock).endswith('[unlocked]>'))
self.assertTrue(RGX_REPR.match(repr(lock))) self.assertTrue(RGX_REPR.match(repr(lock)))
...@@ -55,9 +58,10 @@ class LockTests(test_utils.TestCase): ...@@ -55,9 +58,10 @@ class LockTests(test_utils.TestCase):
self.assertTrue(RGX_REPR.match(repr(lock))) self.assertTrue(RGX_REPR.match(repr(lock)))
def test_lock(self): def test_lock(self):
lock = asyncio.Lock(loop=self.loop)
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
@asyncio.coroutine @asyncio.coroutine
def acquire_lock(): def acquire_lock():
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
...@@ -74,14 +78,14 @@ class LockTests(test_utils.TestCase): ...@@ -74,14 +78,14 @@ class LockTests(test_utils.TestCase):
def test_lock_by_with_statement(self): def test_lock_by_with_statement(self):
loop = asyncio.new_event_loop() # don't use TestLoop quirks loop = asyncio.new_event_loop() # don't use TestLoop quirks
self.set_event_loop(loop) self.set_event_loop(loop)
primitives = [
asyncio.Lock(loop=loop),
asyncio.Condition(loop=loop),
asyncio.Semaphore(loop=loop),
asyncio.BoundedSemaphore(loop=loop),
]
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
primitives = [
asyncio.Lock(loop=loop),
asyncio.Condition(loop=loop),
asyncio.Semaphore(loop=loop),
asyncio.BoundedSemaphore(loop=loop),
]
@asyncio.coroutine @asyncio.coroutine
def test(lock): def test(lock):
yield from asyncio.sleep(0.01) yield from asyncio.sleep(0.01)
...@@ -99,7 +103,8 @@ class LockTests(test_utils.TestCase): ...@@ -99,7 +103,8 @@ class LockTests(test_utils.TestCase):
self.assertFalse(primitive.locked()) self.assertFalse(primitive.locked())
def test_acquire(self): def test_acquire(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
result = [] result = []
self.assertTrue(self.loop.run_until_complete(lock.acquire())) self.assertTrue(self.loop.run_until_complete(lock.acquire()))
...@@ -150,7 +155,8 @@ class LockTests(test_utils.TestCase): ...@@ -150,7 +155,8 @@ class LockTests(test_utils.TestCase):
self.assertTrue(t3.result()) self.assertTrue(t3.result())
def test_acquire_cancel(self): def test_acquire_cancel(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
self.assertTrue(self.loop.run_until_complete(lock.acquire())) self.assertTrue(self.loop.run_until_complete(lock.acquire()))
task = asyncio.Task(lock.acquire(), loop=self.loop) task = asyncio.Task(lock.acquire(), loop=self.loop)
...@@ -175,7 +181,8 @@ class LockTests(test_utils.TestCase): ...@@ -175,7 +181,8 @@ class LockTests(test_utils.TestCase):
# B's waiter; instead, it should move on to C's waiter. # B's waiter; instead, it should move on to C's waiter.
# Setup: A has the lock, b and c are waiting. # Setup: A has the lock, b and c are waiting.
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
async def lockit(name, blocker): async def lockit(name, blocker):
await lock.acquire() await lock.acquire()
...@@ -211,7 +218,8 @@ class LockTests(test_utils.TestCase): ...@@ -211,7 +218,8 @@ class LockTests(test_utils.TestCase):
# Issue 32734 # Issue 32734
# Acquire 4 locks, cancel second, release first # Acquire 4 locks, cancel second, release first
# and 2 locks are taken at once. # and 2 locks are taken at once.
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
lock_count = 0 lock_count = 0
call_count = 0 call_count = 0
...@@ -256,7 +264,8 @@ class LockTests(test_utils.TestCase): ...@@ -256,7 +264,8 @@ class LockTests(test_utils.TestCase):
self.assertTrue(t3.cancelled()) self.assertTrue(t3.cancelled())
def test_finished_waiter_cancelled(self): def test_finished_waiter_cancelled(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
ta = asyncio.Task(lock.acquire(), loop=self.loop) ta = asyncio.Task(lock.acquire(), loop=self.loop)
test_utils.run_briefly(self.loop) test_utils.run_briefly(self.loop)
...@@ -278,12 +287,14 @@ class LockTests(test_utils.TestCase): ...@@ -278,12 +287,14 @@ class LockTests(test_utils.TestCase):
self.assertTrue(tb.cancelled()) self.assertTrue(tb.cancelled())
def test_release_not_acquired(self): def test_release_not_acquired(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
self.assertRaises(RuntimeError, lock.release) self.assertRaises(RuntimeError, lock.release)
def test_release_no_waiters(self): def test_release_no_waiters(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
self.loop.run_until_complete(lock.acquire()) self.loop.run_until_complete(lock.acquire())
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
...@@ -291,9 +302,9 @@ class LockTests(test_utils.TestCase): ...@@ -291,9 +302,9 @@ class LockTests(test_utils.TestCase):
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
def test_context_manager(self): def test_context_manager(self):
lock = asyncio.Lock(loop=self.loop)
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
@asyncio.coroutine @asyncio.coroutine
def acquire_lock(): def acquire_lock():
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
...@@ -305,9 +316,9 @@ class LockTests(test_utils.TestCase): ...@@ -305,9 +316,9 @@ class LockTests(test_utils.TestCase):
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
def test_context_manager_cant_reuse(self): def test_context_manager_cant_reuse(self):
lock = asyncio.Lock(loop=self.loop)
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
@asyncio.coroutine @asyncio.coroutine
def acquire_lock(): def acquire_lock():
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
...@@ -325,7 +336,8 @@ class LockTests(test_utils.TestCase): ...@@ -325,7 +336,8 @@ class LockTests(test_utils.TestCase):
pass pass
def test_context_manager_no_yield(self): def test_context_manager_no_yield(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop)
try: try:
with lock: with lock:
...@@ -346,10 +358,12 @@ class EventTests(test_utils.TestCase): ...@@ -346,10 +358,12 @@ class EventTests(test_utils.TestCase):
def test_ctor_loop(self): def test_ctor_loop(self):
loop = mock.Mock() loop = mock.Mock()
ev = asyncio.Event(loop=loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=loop)
self.assertIs(ev._loop, loop) self.assertIs(ev._loop, loop)
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
self.assertIs(ev._loop, self.loop) self.assertIs(ev._loop, self.loop)
def test_ctor_noloop(self): def test_ctor_noloop(self):
...@@ -358,7 +372,8 @@ class EventTests(test_utils.TestCase): ...@@ -358,7 +372,8 @@ class EventTests(test_utils.TestCase):
self.assertIs(ev._loop, self.loop) self.assertIs(ev._loop, self.loop)
def test_repr(self): def test_repr(self):
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
self.assertTrue(repr(ev).endswith('[unset]>')) self.assertTrue(repr(ev).endswith('[unset]>'))
match = RGX_REPR.match(repr(ev)) match = RGX_REPR.match(repr(ev))
self.assertEqual(match.group('extras'), 'unset') self.assertEqual(match.group('extras'), 'unset')
...@@ -372,7 +387,8 @@ class EventTests(test_utils.TestCase): ...@@ -372,7 +387,8 @@ class EventTests(test_utils.TestCase):
self.assertTrue(RGX_REPR.match(repr(ev))) self.assertTrue(RGX_REPR.match(repr(ev)))
def test_wait(self): def test_wait(self):
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
self.assertFalse(ev.is_set()) self.assertFalse(ev.is_set())
result = [] result = []
...@@ -409,14 +425,16 @@ class EventTests(test_utils.TestCase): ...@@ -409,14 +425,16 @@ class EventTests(test_utils.TestCase):
self.assertIsNone(t3.result()) self.assertIsNone(t3.result())
def test_wait_on_set(self): def test_wait_on_set(self):
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
ev.set() ev.set()
res = self.loop.run_until_complete(ev.wait()) res = self.loop.run_until_complete(ev.wait())
self.assertTrue(res) self.assertTrue(res)
def test_wait_cancel(self): def test_wait_cancel(self):
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
wait = asyncio.Task(ev.wait(), loop=self.loop) wait = asyncio.Task(ev.wait(), loop=self.loop)
self.loop.call_soon(wait.cancel) self.loop.call_soon(wait.cancel)
...@@ -426,7 +444,8 @@ class EventTests(test_utils.TestCase): ...@@ -426,7 +444,8 @@ class EventTests(test_utils.TestCase):
self.assertFalse(ev._waiters) self.assertFalse(ev._waiters)
def test_clear(self): def test_clear(self):
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
self.assertFalse(ev.is_set()) self.assertFalse(ev.is_set())
ev.set() ev.set()
...@@ -436,7 +455,8 @@ class EventTests(test_utils.TestCase): ...@@ -436,7 +455,8 @@ class EventTests(test_utils.TestCase):
self.assertFalse(ev.is_set()) self.assertFalse(ev.is_set())
def test_clear_with_waiters(self): def test_clear_with_waiters(self):
ev = asyncio.Event(loop=self.loop) with self.assertWarns(DeprecationWarning):
ev = asyncio.Event(loop=self.loop)
result = [] result = []
async def c1(result): async def c1(result):
...@@ -472,19 +492,22 @@ class ConditionTests(test_utils.TestCase): ...@@ -472,19 +492,22 @@ class ConditionTests(test_utils.TestCase):
def test_ctor_loop(self): def test_ctor_loop(self):
loop = mock.Mock() loop = mock.Mock()
cond = asyncio.Condition(loop=loop) with self.assertWarns(DeprecationWarning):
self.assertIs(cond._loop, loop) cond = asyncio.Condition(loop=loop)
self.assertIs(cond._loop, loop)
cond = asyncio.Condition(loop=self.loop) cond = asyncio.Condition(loop=self.loop)
self.assertIs(cond._loop, self.loop) self.assertIs(cond._loop, self.loop)
def test_ctor_noloop(self): def test_ctor_noloop(self):
asyncio.set_event_loop(self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition() asyncio.set_event_loop(self.loop)
self.assertIs(cond._loop, self.loop) cond = asyncio.Condition()
self.assertIs(cond._loop, self.loop)
def test_wait(self): def test_wait(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
result = [] result = []
async def c1(result): async def c1(result):
...@@ -547,7 +570,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -547,7 +570,8 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(t3.result()) self.assertTrue(t3.result())
def test_wait_cancel(self): def test_wait_cancel(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
self.loop.run_until_complete(cond.acquire()) self.loop.run_until_complete(cond.acquire())
wait = asyncio.Task(cond.wait(), loop=self.loop) wait = asyncio.Task(cond.wait(), loop=self.loop)
...@@ -559,7 +583,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -559,7 +583,8 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(cond.locked()) self.assertTrue(cond.locked())
def test_wait_cancel_contested(self): def test_wait_cancel_contested(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
self.loop.run_until_complete(cond.acquire()) self.loop.run_until_complete(cond.acquire())
self.assertTrue(cond.locked()) self.assertTrue(cond.locked())
...@@ -585,7 +610,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -585,7 +610,8 @@ class ConditionTests(test_utils.TestCase):
def test_wait_cancel_after_notify(self): def test_wait_cancel_after_notify(self):
# See bpo-32841 # See bpo-32841
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
waited = False waited = False
async def wait_on_cond(): async def wait_on_cond():
...@@ -609,13 +635,15 @@ class ConditionTests(test_utils.TestCase): ...@@ -609,13 +635,15 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(waited) self.assertTrue(waited)
def test_wait_unacquired(self): def test_wait_unacquired(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
self.assertRaises( self.assertRaises(
RuntimeError, RuntimeError,
self.loop.run_until_complete, cond.wait()) self.loop.run_until_complete, cond.wait())
def test_wait_for(self): def test_wait_for(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
presult = False presult = False
def predicate(): def predicate():
...@@ -652,7 +680,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -652,7 +680,8 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(t.result()) self.assertTrue(t.result())
def test_wait_for_unacquired(self): def test_wait_for_unacquired(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
# predicate can return true immediately # predicate can return true immediately
res = self.loop.run_until_complete(cond.wait_for(lambda: [1, 2, 3])) res = self.loop.run_until_complete(cond.wait_for(lambda: [1, 2, 3]))
...@@ -664,7 +693,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -664,7 +693,8 @@ class ConditionTests(test_utils.TestCase):
cond.wait_for(lambda: False)) cond.wait_for(lambda: False))
def test_notify(self): def test_notify(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
result = [] result = []
async def c1(result): async def c1(result):
...@@ -716,7 +746,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -716,7 +746,8 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(t3.result()) self.assertTrue(t3.result())
def test_notify_all(self): def test_notify_all(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
result = [] result = []
...@@ -752,15 +783,18 @@ class ConditionTests(test_utils.TestCase): ...@@ -752,15 +783,18 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(t2.result()) self.assertTrue(t2.result())
def test_notify_unacquired(self): def test_notify_unacquired(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
self.assertRaises(RuntimeError, cond.notify) self.assertRaises(RuntimeError, cond.notify)
def test_notify_all_unacquired(self): def test_notify_all_unacquired(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
self.assertRaises(RuntimeError, cond.notify_all) self.assertRaises(RuntimeError, cond.notify_all)
def test_repr(self): def test_repr(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
self.assertTrue('unlocked' in repr(cond)) self.assertTrue('unlocked' in repr(cond))
self.assertTrue(RGX_REPR.match(repr(cond))) self.assertTrue(RGX_REPR.match(repr(cond)))
...@@ -776,7 +810,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -776,7 +810,8 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(RGX_REPR.match(repr(cond))) self.assertTrue(RGX_REPR.match(repr(cond)))
def test_context_manager(self): def test_context_manager(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
@asyncio.coroutine @asyncio.coroutine
...@@ -790,7 +825,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -790,7 +825,8 @@ class ConditionTests(test_utils.TestCase):
self.assertFalse(cond.locked()) self.assertFalse(cond.locked())
def test_context_manager_no_yield(self): def test_context_manager_no_yield(self):
cond = asyncio.Condition(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(loop=self.loop)
try: try:
with cond: with cond:
...@@ -803,8 +839,9 @@ class ConditionTests(test_utils.TestCase): ...@@ -803,8 +839,9 @@ class ConditionTests(test_utils.TestCase):
self.assertFalse(cond.locked()) self.assertFalse(cond.locked())
def test_explicit_lock(self): def test_explicit_lock(self):
lock = asyncio.Lock(loop=self.loop) with self.assertWarns(DeprecationWarning):
cond = asyncio.Condition(lock, loop=self.loop) lock = asyncio.Lock(loop=self.loop)
cond = asyncio.Condition(lock, loop=self.loop)
self.assertIs(cond._lock, lock) self.assertIs(cond._lock, lock)
self.assertIs(cond._loop, lock._loop) self.assertIs(cond._loop, lock._loop)
...@@ -812,10 +849,10 @@ class ConditionTests(test_utils.TestCase): ...@@ -812,10 +849,10 @@ class ConditionTests(test_utils.TestCase):
def test_ambiguous_loops(self): def test_ambiguous_loops(self):
loop = self.new_test_loop() loop = self.new_test_loop()
self.addCleanup(loop.close) self.addCleanup(loop.close)
with self.assertWarns(DeprecationWarning):
lock = asyncio.Lock(loop=self.loop) lock = asyncio.Lock(loop=self.loop)
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
asyncio.Condition(lock, loop=loop) asyncio.Condition(lock, loop=loop)
def test_timeout_in_block(self): def test_timeout_in_block(self):
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
...@@ -827,7 +864,8 @@ class ConditionTests(test_utils.TestCase): ...@@ -827,7 +864,8 @@ class ConditionTests(test_utils.TestCase):
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
await asyncio.wait_for(condition.wait(), timeout=0.5) await asyncio.wait_for(condition.wait(), timeout=0.5)
loop.run_until_complete(task_timeout()) with self.assertWarns(DeprecationWarning):
loop.run_until_complete(task_timeout())
class SemaphoreTests(test_utils.TestCase): class SemaphoreTests(test_utils.TestCase):
...@@ -838,10 +876,12 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -838,10 +876,12 @@ class SemaphoreTests(test_utils.TestCase):
def test_ctor_loop(self): def test_ctor_loop(self):
loop = mock.Mock() loop = mock.Mock()
sem = asyncio.Semaphore(loop=loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(loop=loop)
self.assertIs(sem._loop, loop) self.assertIs(sem._loop, loop)
sem = asyncio.Semaphore(loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(loop=self.loop)
self.assertIs(sem._loop, self.loop) self.assertIs(sem._loop, self.loop)
def test_ctor_noloop(self): def test_ctor_noloop(self):
...@@ -850,11 +890,13 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -850,11 +890,13 @@ class SemaphoreTests(test_utils.TestCase):
self.assertIs(sem._loop, self.loop) self.assertIs(sem._loop, self.loop)
def test_initial_value_zero(self): def test_initial_value_zero(self):
sem = asyncio.Semaphore(0, loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(0, loop=self.loop)
self.assertTrue(sem.locked()) self.assertTrue(sem.locked())
def test_repr(self): def test_repr(self):
sem = asyncio.Semaphore(loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(loop=self.loop)
self.assertTrue(repr(sem).endswith('[unlocked, value:1]>')) self.assertTrue(repr(sem).endswith('[unlocked, value:1]>'))
self.assertTrue(RGX_REPR.match(repr(sem))) self.assertTrue(RGX_REPR.match(repr(sem)))
...@@ -872,7 +914,8 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -872,7 +914,8 @@ class SemaphoreTests(test_utils.TestCase):
self.assertTrue(RGX_REPR.match(repr(sem))) self.assertTrue(RGX_REPR.match(repr(sem)))
def test_semaphore(self): def test_semaphore(self):
sem = asyncio.Semaphore(loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(loop=self.loop)
self.assertEqual(1, sem._value) self.assertEqual(1, sem._value)
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
...@@ -895,7 +938,8 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -895,7 +938,8 @@ class SemaphoreTests(test_utils.TestCase):
self.assertRaises(ValueError, asyncio.Semaphore, -1) self.assertRaises(ValueError, asyncio.Semaphore, -1)
def test_acquire(self): def test_acquire(self):
sem = asyncio.Semaphore(3, loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(3, loop=self.loop)
result = [] result = []
self.assertTrue(self.loop.run_until_complete(sem.acquire())) self.assertTrue(self.loop.run_until_complete(sem.acquire()))
...@@ -956,7 +1000,8 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -956,7 +1000,8 @@ class SemaphoreTests(test_utils.TestCase):
self.loop.run_until_complete(asyncio.gather(*race_tasks)) self.loop.run_until_complete(asyncio.gather(*race_tasks))
def test_acquire_cancel(self): def test_acquire_cancel(self):
sem = asyncio.Semaphore(loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(loop=self.loop)
self.loop.run_until_complete(sem.acquire()) self.loop.run_until_complete(sem.acquire())
acquire = asyncio.Task(sem.acquire(), loop=self.loop) acquire = asyncio.Task(sem.acquire(), loop=self.loop)
...@@ -968,7 +1013,8 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -968,7 +1013,8 @@ class SemaphoreTests(test_utils.TestCase):
all(waiter.done() for waiter in sem._waiters)) all(waiter.done() for waiter in sem._waiters))
def test_acquire_cancel_before_awoken(self): def test_acquire_cancel_before_awoken(self):
sem = asyncio.Semaphore(value=0, loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(value=0, loop=self.loop)
t1 = asyncio.Task(sem.acquire(), loop=self.loop) t1 = asyncio.Task(sem.acquire(), loop=self.loop)
t2 = asyncio.Task(sem.acquire(), loop=self.loop) t2 = asyncio.Task(sem.acquire(), loop=self.loop)
...@@ -990,7 +1036,8 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -990,7 +1036,8 @@ class SemaphoreTests(test_utils.TestCase):
test_utils.run_briefly(self.loop) test_utils.run_briefly(self.loop)
def test_acquire_hang(self): def test_acquire_hang(self):
sem = asyncio.Semaphore(value=0, loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(value=0, loop=self.loop)
t1 = asyncio.Task(sem.acquire(), loop=self.loop) t1 = asyncio.Task(sem.acquire(), loop=self.loop)
t2 = asyncio.Task(sem.acquire(), loop=self.loop) t2 = asyncio.Task(sem.acquire(), loop=self.loop)
...@@ -1004,12 +1051,14 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -1004,12 +1051,14 @@ class SemaphoreTests(test_utils.TestCase):
self.assertTrue(sem.locked()) self.assertTrue(sem.locked())
def test_release_not_acquired(self): def test_release_not_acquired(self):
sem = asyncio.BoundedSemaphore(loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.BoundedSemaphore(loop=self.loop)
self.assertRaises(ValueError, sem.release) self.assertRaises(ValueError, sem.release)
def test_release_no_waiters(self): def test_release_no_waiters(self):
sem = asyncio.Semaphore(loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(loop=self.loop)
self.loop.run_until_complete(sem.acquire()) self.loop.run_until_complete(sem.acquire())
self.assertTrue(sem.locked()) self.assertTrue(sem.locked())
...@@ -1017,9 +1066,9 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -1017,9 +1066,9 @@ class SemaphoreTests(test_utils.TestCase):
self.assertFalse(sem.locked()) self.assertFalse(sem.locked())
def test_context_manager(self): def test_context_manager(self):
sem = asyncio.Semaphore(2, loop=self.loop)
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(2, loop=self.loop)
@asyncio.coroutine @asyncio.coroutine
def acquire_lock(): def acquire_lock():
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
...@@ -1035,7 +1084,8 @@ class SemaphoreTests(test_utils.TestCase): ...@@ -1035,7 +1084,8 @@ class SemaphoreTests(test_utils.TestCase):
self.assertEqual(2, sem._value) self.assertEqual(2, sem._value)
def test_context_manager_no_yield(self): def test_context_manager_no_yield(self):
sem = asyncio.Semaphore(2, loop=self.loop) with self.assertWarns(DeprecationWarning):
sem = asyncio.Semaphore(2, loop=self.loop)
try: try:
with sem: with sem:
......
...@@ -43,12 +43,13 @@ class BaseTest(test_utils.TestCase): ...@@ -43,12 +43,13 @@ class BaseTest(test_utils.TestCase):
class LockTests(BaseTest): class LockTests(BaseTest):
def test_context_manager_async_with(self): def test_context_manager_async_with(self):
primitives = [ with self.assertWarns(DeprecationWarning):
asyncio.Lock(loop=self.loop), primitives = [
asyncio.Condition(loop=self.loop), asyncio.Lock(loop=self.loop),
asyncio.Semaphore(loop=self.loop), asyncio.Condition(loop=self.loop),
asyncio.BoundedSemaphore(loop=self.loop), asyncio.Semaphore(loop=self.loop),
] asyncio.BoundedSemaphore(loop=self.loop),
]
async def test(lock): async def test(lock):
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
...@@ -65,12 +66,13 @@ class LockTests(BaseTest): ...@@ -65,12 +66,13 @@ class LockTests(BaseTest):
self.assertFalse(primitive.locked()) self.assertFalse(primitive.locked())
def test_context_manager_with_await(self): def test_context_manager_with_await(self):
primitives = [ with self.assertWarns(DeprecationWarning):
asyncio.Lock(loop=self.loop), primitives = [
asyncio.Condition(loop=self.loop), asyncio.Lock(loop=self.loop),
asyncio.Semaphore(loop=self.loop), asyncio.Condition(loop=self.loop),
asyncio.BoundedSemaphore(loop=self.loop), asyncio.Semaphore(loop=self.loop),
] asyncio.BoundedSemaphore(loop=self.loop),
]
async def test(lock): async def test(lock):
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
......
...@@ -35,7 +35,8 @@ class QueueBasicTests(_QueueTestBase): ...@@ -35,7 +35,8 @@ class QueueBasicTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(loop=loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
self.assertTrue(fn(q).startswith('<Queue'), fn(q)) self.assertTrue(fn(q).startswith('<Queue'), fn(q))
id_is_present = hex(id(q)) in fn(q) id_is_present = hex(id(q)) in fn(q)
self.assertEqual(expect_id, id_is_present) self.assertEqual(expect_id, id_is_present)
...@@ -50,7 +51,8 @@ class QueueBasicTests(_QueueTestBase): ...@@ -50,7 +51,8 @@ class QueueBasicTests(_QueueTestBase):
# resume q.get coroutine to finish generator # resume q.get coroutine to finish generator
q.put_nowait(0) q.put_nowait(0)
loop.run_until_complete(add_getter()) with self.assertWarns(DeprecationWarning):
loop.run_until_complete(add_getter())
async def add_putter(): async def add_putter():
q = asyncio.Queue(maxsize=1, loop=loop) q = asyncio.Queue(maxsize=1, loop=loop)
...@@ -63,23 +65,26 @@ class QueueBasicTests(_QueueTestBase): ...@@ -63,23 +65,26 @@ class QueueBasicTests(_QueueTestBase):
# resume q.put coroutine to finish generator # resume q.put coroutine to finish generator
q.get_nowait() q.get_nowait()
loop.run_until_complete(add_putter()) with self.assertWarns(DeprecationWarning):
loop.run_until_complete(add_putter())
q = asyncio.Queue(loop=loop) q = asyncio.Queue(loop=loop)
q.put_nowait(1) q.put_nowait(1)
self.assertTrue('_queue=[1]' in fn(q)) self.assertTrue('_queue=[1]' in fn(q))
def test_ctor_loop(self): def test_ctor_loop(self):
loop = mock.Mock() loop = mock.Mock()
q = asyncio.Queue(loop=loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
self.assertIs(q._loop, loop) self.assertIs(q._loop, loop)
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
self.assertIs(q._loop, self.loop) self.assertIs(q._loop, self.loop)
def test_ctor_noloop(self): def test_ctor_noloop(self):
asyncio.set_event_loop(self.loop) asyncio.set_event_loop(self.loop)
q = asyncio.Queue() with self.assertWarns(DeprecationWarning):
q = asyncio.Queue()
self.assertIs(q._loop, self.loop) self.assertIs(q._loop, self.loop)
def test_repr(self): def test_repr(self):
...@@ -89,7 +94,8 @@ class QueueBasicTests(_QueueTestBase): ...@@ -89,7 +94,8 @@ class QueueBasicTests(_QueueTestBase):
self._test_repr_or_str(str, False) self._test_repr_or_str(str, False)
def test_empty(self): def test_empty(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
self.assertTrue(q.empty()) self.assertTrue(q.empty())
q.put_nowait(1) q.put_nowait(1)
self.assertFalse(q.empty()) self.assertFalse(q.empty())
...@@ -97,15 +103,18 @@ class QueueBasicTests(_QueueTestBase): ...@@ -97,15 +103,18 @@ class QueueBasicTests(_QueueTestBase):
self.assertTrue(q.empty()) self.assertTrue(q.empty())
def test_full(self): def test_full(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
self.assertFalse(q.full()) self.assertFalse(q.full())
q = asyncio.Queue(maxsize=1, loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=1, loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
self.assertTrue(q.full()) self.assertTrue(q.full())
def test_order(self): def test_order(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
for i in [1, 3, 2]: for i in [1, 3, 2]:
q.put_nowait(i) q.put_nowait(i)
...@@ -123,7 +132,8 @@ class QueueBasicTests(_QueueTestBase): ...@@ -123,7 +132,8 @@ class QueueBasicTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(maxsize=2, loop=loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=2, loop=loop)
self.assertEqual(2, q.maxsize) self.assertEqual(2, q.maxsize)
have_been_put = [] have_been_put = []
...@@ -157,7 +167,8 @@ class QueueBasicTests(_QueueTestBase): ...@@ -157,7 +167,8 @@ class QueueBasicTests(_QueueTestBase):
class QueueGetTests(_QueueTestBase): class QueueGetTests(_QueueTestBase):
def test_blocking_get(self): def test_blocking_get(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
async def queue_get(): async def queue_get():
...@@ -167,7 +178,8 @@ class QueueGetTests(_QueueTestBase): ...@@ -167,7 +178,8 @@ class QueueGetTests(_QueueTestBase):
self.assertEqual(1, res) self.assertEqual(1, res)
def test_get_with_putters(self): def test_get_with_putters(self):
q = asyncio.Queue(1, loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(1, loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
waiter = asyncio.Future(loop=self.loop) waiter = asyncio.Future(loop=self.loop)
...@@ -187,8 +199,9 @@ class QueueGetTests(_QueueTestBase): ...@@ -187,8 +199,9 @@ class QueueGetTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(loop=loop) with self.assertWarns(DeprecationWarning):
started = asyncio.Event(loop=loop) q = asyncio.Queue(loop=loop)
started = asyncio.Event(loop=loop)
finished = False finished = False
async def queue_get(): async def queue_get():
...@@ -212,12 +225,14 @@ class QueueGetTests(_QueueTestBase): ...@@ -212,12 +225,14 @@ class QueueGetTests(_QueueTestBase):
self.assertAlmostEqual(0.01, loop.time()) self.assertAlmostEqual(0.01, loop.time())
def test_nonblocking_get(self): def test_nonblocking_get(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
self.assertEqual(1, q.get_nowait()) self.assertEqual(1, q.get_nowait())
def test_nonblocking_get_exception(self): def test_nonblocking_get_exception(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
self.assertRaises(asyncio.QueueEmpty, q.get_nowait) self.assertRaises(asyncio.QueueEmpty, q.get_nowait)
def test_get_cancelled(self): def test_get_cancelled(self):
...@@ -231,7 +246,8 @@ class QueueGetTests(_QueueTestBase): ...@@ -231,7 +246,8 @@ class QueueGetTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(loop=loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
async def queue_get(): async def queue_get():
return await asyncio.wait_for(q.get(), 0.051) return await asyncio.wait_for(q.get(), 0.051)
...@@ -246,7 +262,8 @@ class QueueGetTests(_QueueTestBase): ...@@ -246,7 +262,8 @@ class QueueGetTests(_QueueTestBase):
self.assertAlmostEqual(0.06, loop.time()) self.assertAlmostEqual(0.06, loop.time())
def test_get_cancelled_race(self): def test_get_cancelled_race(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
t1 = asyncio.Task(q.get(), loop=self.loop) t1 = asyncio.Task(q.get(), loop=self.loop)
t2 = asyncio.Task(q.get(), loop=self.loop) t2 = asyncio.Task(q.get(), loop=self.loop)
...@@ -260,7 +277,8 @@ class QueueGetTests(_QueueTestBase): ...@@ -260,7 +277,8 @@ class QueueGetTests(_QueueTestBase):
self.assertEqual(t2.result(), 'a') self.assertEqual(t2.result(), 'a')
def test_get_with_waiting_putters(self): def test_get_with_waiting_putters(self):
q = asyncio.Queue(loop=self.loop, maxsize=1) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop, maxsize=1)
asyncio.Task(q.put('a'), loop=self.loop) asyncio.Task(q.put('a'), loop=self.loop)
asyncio.Task(q.put('b'), loop=self.loop) asyncio.Task(q.put('b'), loop=self.loop)
test_utils.run_briefly(self.loop) test_utils.run_briefly(self.loop)
...@@ -280,7 +298,9 @@ class QueueGetTests(_QueueTestBase): ...@@ -280,7 +298,9 @@ class QueueGetTests(_QueueTestBase):
queue_size = 1 queue_size = 1
producer_num_items = 5 producer_num_items = 5
q = asyncio.Queue(queue_size, loop=self.loop)
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(queue_size, loop=self.loop)
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.gather(producer(q, producer_num_items), asyncio.gather(producer(q, producer_num_items),
...@@ -301,7 +321,8 @@ class QueueGetTests(_QueueTestBase): ...@@ -301,7 +321,8 @@ class QueueGetTests(_QueueTestBase):
except asyncio.TimeoutError: except asyncio.TimeoutError:
pass pass
queue = asyncio.Queue(loop=self.loop, maxsize=5) with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(loop=self.loop, maxsize=5)
self.loop.run_until_complete(self.loop.create_task(consumer(queue))) self.loop.run_until_complete(self.loop.create_task(consumer(queue)))
self.assertEqual(len(queue._getters), 0) self.assertEqual(len(queue._getters), 0)
...@@ -309,7 +330,8 @@ class QueueGetTests(_QueueTestBase): ...@@ -309,7 +330,8 @@ class QueueGetTests(_QueueTestBase):
class QueuePutTests(_QueueTestBase): class QueuePutTests(_QueueTestBase):
def test_blocking_put(self): def test_blocking_put(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
async def queue_put(): async def queue_put():
# No maxsize, won't block. # No maxsize, won't block.
...@@ -326,8 +348,9 @@ class QueuePutTests(_QueueTestBase): ...@@ -326,8 +348,9 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(maxsize=1, loop=loop) with self.assertWarns(DeprecationWarning):
started = asyncio.Event(loop=loop) q = asyncio.Queue(maxsize=1, loop=loop)
started = asyncio.Event(loop=loop)
finished = False finished = False
async def queue_put(): async def queue_put():
...@@ -349,7 +372,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -349,7 +372,8 @@ class QueuePutTests(_QueueTestBase):
self.assertAlmostEqual(0.01, loop.time()) self.assertAlmostEqual(0.01, loop.time())
def test_nonblocking_put(self): def test_nonblocking_put(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
self.assertEqual(1, q.get_nowait()) self.assertEqual(1, q.get_nowait())
...@@ -360,7 +384,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -360,7 +384,8 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(loop=loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
reader = loop.create_task(q.get()) reader = loop.create_task(q.get())
...@@ -389,7 +414,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -389,7 +414,8 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
loop.set_debug(True) loop.set_debug(True)
q = asyncio.Queue(loop=loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
reader1 = loop.create_task(q.get()) reader1 = loop.create_task(q.get())
reader2 = loop.create_task(q.get()) reader2 = loop.create_task(q.get())
...@@ -418,7 +444,9 @@ class QueuePutTests(_QueueTestBase): ...@@ -418,7 +444,9 @@ class QueuePutTests(_QueueTestBase):
yield 0.1 yield 0.1
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
q = asyncio.Queue(1, loop=loop)
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(1, loop=loop)
q.put_nowait(1) q.put_nowait(1)
...@@ -442,18 +470,21 @@ class QueuePutTests(_QueueTestBase): ...@@ -442,18 +470,21 @@ class QueuePutTests(_QueueTestBase):
self.assertEqual(q.qsize(), 0) self.assertEqual(q.qsize(), 0)
def test_nonblocking_put_exception(self): def test_nonblocking_put_exception(self):
q = asyncio.Queue(maxsize=1, loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=1, loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
self.assertRaises(asyncio.QueueFull, q.put_nowait, 2) self.assertRaises(asyncio.QueueFull, q.put_nowait, 2)
def test_float_maxsize(self): def test_float_maxsize(self):
q = asyncio.Queue(maxsize=1.3, loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=1.3, loop=self.loop)
q.put_nowait(1) q.put_nowait(1)
q.put_nowait(2) q.put_nowait(2)
self.assertTrue(q.full()) self.assertTrue(q.full())
self.assertRaises(asyncio.QueueFull, q.put_nowait, 3) self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)
q = asyncio.Queue(maxsize=1.3, loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=1.3, loop=self.loop)
async def queue_put(): async def queue_put():
await q.put(1) await q.put(1)
...@@ -462,7 +493,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -462,7 +493,8 @@ class QueuePutTests(_QueueTestBase):
self.loop.run_until_complete(queue_put()) self.loop.run_until_complete(queue_put())
def test_put_cancelled(self): def test_put_cancelled(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
async def queue_put(): async def queue_put():
await q.put(1) await q.put(1)
...@@ -477,7 +509,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -477,7 +509,8 @@ class QueuePutTests(_QueueTestBase):
self.assertTrue(t.result()) self.assertTrue(t.result())
def test_put_cancelled_race(self): def test_put_cancelled_race(self):
q = asyncio.Queue(loop=self.loop, maxsize=1) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop, maxsize=1)
put_a = asyncio.Task(q.put('a'), loop=self.loop) put_a = asyncio.Task(q.put('a'), loop=self.loop)
put_b = asyncio.Task(q.put('b'), loop=self.loop) put_b = asyncio.Task(q.put('b'), loop=self.loop)
...@@ -497,7 +530,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -497,7 +530,8 @@ class QueuePutTests(_QueueTestBase):
self.loop.run_until_complete(put_b) self.loop.run_until_complete(put_b)
def test_put_with_waiting_getters(self): def test_put_with_waiting_getters(self):
q = asyncio.Queue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
t = asyncio.Task(q.get(), loop=self.loop) t = asyncio.Task(q.get(), loop=self.loop)
test_utils.run_briefly(self.loop) test_utils.run_briefly(self.loop)
self.loop.run_until_complete(q.put('a')) self.loop.run_until_complete(q.put('a'))
...@@ -506,7 +540,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -506,7 +540,8 @@ class QueuePutTests(_QueueTestBase):
def test_why_are_putters_waiting(self): def test_why_are_putters_waiting(self):
# From issue #265. # From issue #265.
queue = asyncio.Queue(2, loop=self.loop) with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(2, loop=self.loop)
async def putter(item): async def putter(item):
await queue.put(item) await queue.put(item)
...@@ -532,7 +567,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -532,7 +567,8 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(a_generator) loop = self.new_test_loop(a_generator)
# Full queue. # Full queue.
queue = asyncio.Queue(loop=loop, maxsize=1) with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(loop=loop, maxsize=1)
queue.put_nowait(1) queue.put_nowait(1)
# Task waiting for space to put an item in the queue. # Task waiting for space to put an item in the queue.
...@@ -555,7 +591,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -555,7 +591,8 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
# Full Queue. # Full Queue.
queue = asyncio.Queue(1, loop=loop) with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(1, loop=loop)
queue.put_nowait(1) queue.put_nowait(1)
# Task waiting for space to put a item in the queue. # Task waiting for space to put a item in the queue.
...@@ -578,7 +615,8 @@ class QueuePutTests(_QueueTestBase): ...@@ -578,7 +615,8 @@ class QueuePutTests(_QueueTestBase):
class LifoQueueTests(_QueueTestBase): class LifoQueueTests(_QueueTestBase):
def test_order(self): def test_order(self):
q = asyncio.LifoQueue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.LifoQueue(loop=self.loop)
for i in [1, 3, 2]: for i in [1, 3, 2]:
q.put_nowait(i) q.put_nowait(i)
...@@ -589,7 +627,8 @@ class LifoQueueTests(_QueueTestBase): ...@@ -589,7 +627,8 @@ class LifoQueueTests(_QueueTestBase):
class PriorityQueueTests(_QueueTestBase): class PriorityQueueTests(_QueueTestBase):
def test_order(self): def test_order(self):
q = asyncio.PriorityQueue(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = asyncio.PriorityQueue(loop=self.loop)
for i in [1, 3, 2]: for i in [1, 3, 2]:
q.put_nowait(i) q.put_nowait(i)
...@@ -602,11 +641,13 @@ class _QueueJoinTestMixin: ...@@ -602,11 +641,13 @@ class _QueueJoinTestMixin:
q_class = None q_class = None
def test_task_done_underflow(self): def test_task_done_underflow(self):
q = self.q_class(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = self.q_class(loop=self.loop)
self.assertRaises(ValueError, q.task_done) self.assertRaises(ValueError, q.task_done)
def test_task_done(self): def test_task_done(self):
q = self.q_class(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = self.q_class(loop=self.loop)
for i in range(100): for i in range(100):
q.put_nowait(i) q.put_nowait(i)
...@@ -641,7 +682,8 @@ class _QueueJoinTestMixin: ...@@ -641,7 +682,8 @@ class _QueueJoinTestMixin:
self.loop.run_until_complete(asyncio.wait(tasks)) self.loop.run_until_complete(asyncio.wait(tasks))
def test_join_empty_queue(self): def test_join_empty_queue(self):
q = self.q_class(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = self.q_class(loop=self.loop)
# Test that a queue join()s successfully, and before anything else # Test that a queue join()s successfully, and before anything else
# (done twice for insurance). # (done twice for insurance).
...@@ -653,7 +695,8 @@ class _QueueJoinTestMixin: ...@@ -653,7 +695,8 @@ class _QueueJoinTestMixin:
self.loop.run_until_complete(join()) self.loop.run_until_complete(join())
def test_format(self): def test_format(self):
q = self.q_class(loop=self.loop) with self.assertWarns(DeprecationWarning):
q = self.q_class(loop=self.loop)
self.assertEqual(q._format(), 'maxsize=0') self.assertEqual(q._format(), 'maxsize=0')
q._unfinished_tasks = 2 q._unfinished_tasks = 2
......
...@@ -1231,15 +1231,16 @@ class BaseTaskTests: ...@@ -1231,15 +1231,16 @@ class BaseTaskTests:
for f in asyncio.as_completed([b, c, a], loop=loop): for f in asyncio.as_completed([b, c, a], loop=loop):
values.append(await f) values.append(await f)
return values return values
with self.assertWarns(DeprecationWarning):
res = loop.run_until_complete(self.new_task(loop, foo())) res = loop.run_until_complete(self.new_task(loop, foo()))
self.assertAlmostEqual(0.15, loop.time()) self.assertAlmostEqual(0.15, loop.time())
self.assertTrue('a' in res[:2]) self.assertTrue('a' in res[:2])
self.assertTrue('b' in res[:2]) self.assertTrue('b' in res[:2])
self.assertEqual(res[2], 'c') self.assertEqual(res[2], 'c')
# Doing it again should take no time and exercise a different path. # Doing it again should take no time and exercise a different path.
res = loop.run_until_complete(self.new_task(loop, foo())) with self.assertWarns(DeprecationWarning):
res = loop.run_until_complete(self.new_task(loop, foo()))
self.assertAlmostEqual(0.15, loop.time()) self.assertAlmostEqual(0.15, loop.time())
def test_as_completed_with_timeout(self): def test_as_completed_with_timeout(self):
...@@ -1267,7 +1268,8 @@ class BaseTaskTests: ...@@ -1267,7 +1268,8 @@ class BaseTaskTests:
values.append((2, exc)) values.append((2, exc))
return values return values
res = loop.run_until_complete(self.new_task(loop, foo())) with self.assertWarns(DeprecationWarning):
res = loop.run_until_complete(self.new_task(loop, foo()))
self.assertEqual(len(res), 2, res) self.assertEqual(len(res), 2, res)
self.assertEqual(res[0], (1, 'a')) self.assertEqual(res[0], (1, 'a'))
self.assertEqual(res[1][0], 2) self.assertEqual(res[1][0], 2)
...@@ -1294,7 +1296,8 @@ class BaseTaskTests: ...@@ -1294,7 +1296,8 @@ class BaseTaskTests:
v = await f v = await f
self.assertEqual(v, 'a') self.assertEqual(v, 'a')
loop.run_until_complete(self.new_task(loop, foo())) with self.assertWarns(DeprecationWarning):
loop.run_until_complete(self.new_task(loop, foo()))
def test_as_completed_reverse_wait(self): def test_as_completed_reverse_wait(self):
...@@ -1308,7 +1311,9 @@ class BaseTaskTests: ...@@ -1308,7 +1311,9 @@ class BaseTaskTests:
a = asyncio.sleep(0.05, 'a') a = asyncio.sleep(0.05, 'a')
b = asyncio.sleep(0.10, 'b') b = asyncio.sleep(0.10, 'b')
fs = {a, b} fs = {a, b}
futs = list(asyncio.as_completed(fs, loop=loop))
with self.assertWarns(DeprecationWarning):
futs = list(asyncio.as_completed(fs, loop=loop))
self.assertEqual(len(futs), 2) self.assertEqual(len(futs), 2)
x = loop.run_until_complete(futs[1]) x = loop.run_until_complete(futs[1])
...@@ -1333,7 +1338,8 @@ class BaseTaskTests: ...@@ -1333,7 +1338,8 @@ class BaseTaskTests:
a = asyncio.sleep(0.05, 'a') a = asyncio.sleep(0.05, 'a')
b = asyncio.sleep(0.05, 'b') b = asyncio.sleep(0.05, 'b')
fs = {a, b} fs = {a, b}
futs = list(asyncio.as_completed(fs, loop=loop)) with self.assertWarns(DeprecationWarning):
futs = list(asyncio.as_completed(fs, loop=loop))
self.assertEqual(len(futs), 2) self.assertEqual(len(futs), 2)
waiter = asyncio.wait(futs) waiter = asyncio.wait(futs)
done, pending = loop.run_until_complete(waiter) done, pending = loop.run_until_complete(waiter)
...@@ -1356,8 +1362,9 @@ class BaseTaskTests: ...@@ -1356,8 +1362,9 @@ class BaseTaskTests:
result.append((yield from f)) result.append((yield from f))
return result return result
fut = self.new_task(self.loop, runner()) with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(fut) fut = self.new_task(self.loop, runner())
self.loop.run_until_complete(fut)
result = fut.result() result = fut.result()
self.assertEqual(set(result), {'ham', 'spam'}) self.assertEqual(set(result), {'ham', 'spam'})
self.assertEqual(len(result), 2) self.assertEqual(len(result), 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment