summaryrefslogtreecommitdiff
path: root/Lib/test/test_asyncio/test_queues.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio/test_queues.py')
-rw-r--r--Lib/test/test_asyncio/test_queues.py152
1 files changed, 54 insertions, 98 deletions
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
index 5c9aaa82c3..dc97673b6f 100644
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -35,14 +35,13 @@ class QueueBasicTests(_QueueTestBase):
loop = self.new_test_loop(gen)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=loop)
+ q = asyncio.Queue()
self.assertTrue(fn(q).startswith('<Queue'), fn(q))
id_is_present = hex(id(q)) in fn(q)
self.assertEqual(expect_id, id_is_present)
async def add_getter():
- q = asyncio.Queue(loop=loop)
+ q = asyncio.Queue()
# Start a task that waits to get.
loop.create_task(q.get())
# Let it start waiting.
@@ -51,11 +50,10 @@ class QueueBasicTests(_QueueTestBase):
# resume q.get coroutine to finish generator
q.put_nowait(0)
- with self.assertWarns(DeprecationWarning):
- loop.run_until_complete(add_getter())
+ loop.run_until_complete(add_getter())
async def add_putter():
- q = asyncio.Queue(maxsize=1, loop=loop)
+ q = asyncio.Queue(maxsize=1)
q.put_nowait(1)
# Start a task that waits to put.
loop.create_task(q.put(2))
@@ -65,27 +63,11 @@ 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)
+ loop.run_until_complete(add_putter())
+ q = asyncio.Queue()
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)
- q = asyncio.Queue()
- self.assertIs(q._loop, self.loop)
-
def test_repr(self):
self._test_repr_or_str(repr, True)
@@ -93,8 +75,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)
+ q = asyncio.Queue()
self.assertTrue(q.empty())
q.put_nowait(1)
self.assertFalse(q.empty())
@@ -102,18 +83,15 @@ class QueueBasicTests(_QueueTestBase):
self.assertTrue(q.empty())
def test_full(self):
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=self.loop)
+ q = asyncio.Queue()
self.assertFalse(q.full())
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(maxsize=1, loop=self.loop)
+ q = asyncio.Queue(maxsize=1)
q.put_nowait(1)
self.assertTrue(q.full())
def test_order(self):
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=self.loop)
+ q = asyncio.Queue()
for i in [1, 3, 2]:
q.put_nowait(i)
@@ -131,8 +109,7 @@ class QueueBasicTests(_QueueTestBase):
loop = self.new_test_loop(gen)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(maxsize=2, loop=loop)
+ q = asyncio.Queue(maxsize=2)
self.assertEqual(2, q.maxsize)
have_been_put = []
@@ -166,8 +143,7 @@ class QueueBasicTests(_QueueTestBase):
class QueueGetTests(_QueueTestBase):
def test_blocking_get(self):
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=self.loop)
+ q = asyncio.Queue()
q.put_nowait(1)
async def queue_get():
@@ -177,8 +153,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 = asyncio.Queue(1)
q.put_nowait(1)
waiter = self.loop.create_future()
@@ -198,9 +173,8 @@ class QueueGetTests(_QueueTestBase):
loop = self.new_test_loop(gen)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=loop)
- started = asyncio.Event(loop=loop)
+ q = asyncio.Queue()
+ started = asyncio.Event()
finished = False
async def queue_get():
@@ -224,14 +198,12 @@ 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 = asyncio.Queue()
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)
+ q = asyncio.Queue()
self.assertRaises(asyncio.QueueEmpty, q.get_nowait)
def test_get_cancelled(self):
@@ -245,8 +217,7 @@ class QueueGetTests(_QueueTestBase):
loop = self.new_test_loop(gen)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=loop)
+ q = asyncio.Queue()
async def queue_get():
return await asyncio.wait_for(q.get(), 0.051)
@@ -261,8 +232,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)
+ q = asyncio.Queue()
t1 = self.loop.create_task(q.get())
t2 = self.loop.create_task(q.get())
@@ -276,8 +246,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)
+ q = asyncio.Queue(maxsize=1)
self.loop.create_task(q.put('a'))
self.loop.create_task(q.put('b'))
test_utils.run_briefly(self.loop)
@@ -298,8 +267,12 @@ class QueueGetTests(_QueueTestBase):
queue_size = 1
producer_num_items = 5
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(queue_size, loop=self.loop)
+ async def create_queue():
+ queue = asyncio.Queue(queue_size)
+ queue._get_loop()
+ return queue
+
+ q = self.loop.run_until_complete(create_queue())
self.loop.run_until_complete(
asyncio.gather(producer(q, producer_num_items),
@@ -320,8 +293,7 @@ class QueueGetTests(_QueueTestBase):
except asyncio.TimeoutError:
pass
- with self.assertWarns(DeprecationWarning):
- queue = asyncio.Queue(loop=self.loop, maxsize=5)
+ queue = asyncio.Queue(maxsize=5)
self.loop.run_until_complete(self.loop.create_task(consumer(queue)))
self.assertEqual(len(queue._getters), 0)
@@ -329,8 +301,7 @@ class QueueGetTests(_QueueTestBase):
class QueuePutTests(_QueueTestBase):
def test_blocking_put(self):
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=self.loop)
+ q = asyncio.Queue()
async def queue_put():
# No maxsize, won't block.
@@ -347,9 +318,8 @@ 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)
+ q = asyncio.Queue(maxsize=1)
+ started = asyncio.Event()
finished = False
async def queue_put():
@@ -371,8 +341,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 = asyncio.Queue()
q.put_nowait(1)
self.assertEqual(1, q.get_nowait())
@@ -383,8 +352,7 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=loop)
+ q = asyncio.Queue()
reader = loop.create_task(q.get())
@@ -413,8 +381,7 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen)
loop.set_debug(True)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(loop=loop)
+ q = asyncio.Queue()
reader1 = loop.create_task(q.get())
reader2 = loop.create_task(q.get())
@@ -444,8 +411,7 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen)
- with self.assertWarns(DeprecationWarning):
- q = asyncio.Queue(1, loop=loop)
+ q = asyncio.Queue(1)
q.put_nowait(1)
@@ -469,21 +435,18 @@ 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 = asyncio.Queue(maxsize=1, )
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 = asyncio.Queue(maxsize=1.3, )
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)
+ q = asyncio.Queue(maxsize=1.3, )
async def queue_put():
await q.put(1)
@@ -492,8 +455,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)
+ q = asyncio.Queue()
async def queue_put():
await q.put(1)
@@ -508,8 +470,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)
+ q = asyncio.Queue(maxsize=1)
put_a = self.loop.create_task(q.put('a'))
put_b = self.loop.create_task(q.put('b'))
@@ -529,8 +490,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)
+ q = asyncio.Queue()
t = self.loop.create_task(q.get())
test_utils.run_briefly(self.loop)
self.loop.run_until_complete(q.put('a'))
@@ -539,8 +499,12 @@ 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 create_queue():
+ q = asyncio.Queue(2)
+ q._get_loop()
+ return q
+
+ queue = self.loop.run_until_complete(create_queue())
async def putter(item):
await queue.put(item)
@@ -566,8 +530,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 = asyncio.Queue(maxsize=1)
queue.put_nowait(1)
# Task waiting for space to put an item in the queue.
@@ -590,8 +553,7 @@ class QueuePutTests(_QueueTestBase):
loop = self.new_test_loop(gen)
# Full Queue.
- with self.assertWarns(DeprecationWarning):
- queue = asyncio.Queue(1, loop=loop)
+ queue = asyncio.Queue(1)
queue.put_nowait(1)
# Task waiting for space to put a item in the queue.
@@ -614,8 +576,7 @@ class QueuePutTests(_QueueTestBase):
class LifoQueueTests(_QueueTestBase):
def test_order(self):
- with self.assertWarns(DeprecationWarning):
- q = asyncio.LifoQueue(loop=self.loop)
+ q = asyncio.LifoQueue()
for i in [1, 3, 2]:
q.put_nowait(i)
@@ -626,8 +587,7 @@ class LifoQueueTests(_QueueTestBase):
class PriorityQueueTests(_QueueTestBase):
def test_order(self):
- with self.assertWarns(DeprecationWarning):
- q = asyncio.PriorityQueue(loop=self.loop)
+ q = asyncio.PriorityQueue()
for i in [1, 3, 2]:
q.put_nowait(i)
@@ -640,13 +600,11 @@ class _QueueJoinTestMixin:
q_class = None
def test_task_done_underflow(self):
- with self.assertWarns(DeprecationWarning):
- q = self.q_class(loop=self.loop)
+ q = self.q_class()
self.assertRaises(ValueError, q.task_done)
def test_task_done(self):
- with self.assertWarns(DeprecationWarning):
- q = self.q_class(loop=self.loop)
+ q = self.q_class()
for i in range(100):
q.put_nowait(i)
@@ -681,8 +639,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)
+ q = self.q_class()
# Test that a queue join()s successfully, and before anything else
# (done twice for insurance).
@@ -694,8 +651,7 @@ class _QueueJoinTestMixin:
self.loop.run_until_complete(join())
def test_format(self):
- with self.assertWarns(DeprecationWarning):
- q = self.q_class(loop=self.loop)
+ q = self.q_class()
self.assertEqual(q._format(), 'maxsize=0')
q._unfinished_tasks = 2