Skip to content
Closed
Prev Previous commit
Next Next commit
Remove assertWarns not applied on queues test
  • Loading branch information
eamanu committed Mar 16, 2020
commit dd6dec31d366a97bd662064d89a695f76fcfebae
130 changes: 44 additions & 86 deletions Lib/test/test_asyncio/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def gen():

loop = self.new_test_loop(gen)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
q = asyncio.Queue(loop=loop)
self.assertTrue(fn(q).startswith('<Queue'), fn(q))
id_is_present = hex(id(q)) in fn(q)
self.assertEqual(expect_id, id_is_present)
Expand All @@ -51,8 +50,7 @@ async def add_getter():
# 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)
Expand All @@ -65,20 +63,17 @@ async def add_putter():
# 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(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)
q = asyncio.Queue(loop=loop)
self.assertIs(q._loop, loop)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q = asyncio.Queue(loop=self.loop)
self.assertIs(q._loop, self.loop)

def test_ctor_noloop(self):
Expand All @@ -93,27 +88,23 @@ def test_str(self):
self._test_repr_or_str(str, False)

def test_empty(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q = asyncio.Queue(loop=self.loop)
self.assertTrue(q.empty())
q.put_nowait(1)
self.assertFalse(q.empty())
self.assertEqual(1, q.get_nowait())
self.assertTrue(q.empty())

def test_full(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q = asyncio.Queue(loop=self.loop)
self.assertFalse(q.full())

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=1, loop=self.loop)
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)
q = asyncio.Queue(loop=self.loop)
for i in [1, 3, 2]:
q.put_nowait(i)

Expand All @@ -131,8 +122,7 @@ def gen():

loop = self.new_test_loop(gen)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(maxsize=2, loop=loop)
q = asyncio.Queue(maxsize=2, loop=loop)
self.assertEqual(2, q.maxsize)
have_been_put = []

Expand Down Expand Up @@ -166,8 +156,7 @@ async def test():
class QueueGetTests(_QueueTestBase):

def test_blocking_get(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q = asyncio.Queue(loop=self.loop)
q.put_nowait(1)

async def queue_get():
Expand All @@ -177,8 +166,7 @@ async def queue_get():
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, loop=self.loop)
q.put_nowait(1)

waiter = self.loop.create_future()
Expand All @@ -198,9 +186,8 @@ def gen():

loop = self.new_test_loop(gen)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
started = asyncio.Event(loop=loop)
q = asyncio.Queue(loop=loop)
started = asyncio.Event(loop=loop)
finished = False

async def queue_get():
Expand All @@ -224,14 +211,12 @@ async def queue_put():
self.assertAlmostEqual(0.01, loop.time())

def test_nonblocking_get(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
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)
q = asyncio.Queue(loop=self.loop)
self.assertRaises(asyncio.QueueEmpty, q.get_nowait)

def test_get_cancelled(self):
Expand All @@ -245,8 +230,7 @@ def gen():

loop = self.new_test_loop(gen)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
q = asyncio.Queue(loop=loop)

async def queue_get():
return await asyncio.wait_for(q.get(), 0.051)
Expand All @@ -261,8 +245,7 @@ async def test():
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(loop=self.loop)

t1 = self.loop.create_task(q.get())
t2 = self.loop.create_task(q.get())
Expand All @@ -276,8 +259,7 @@ def test_get_cancelled_race(self):
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(loop=self.loop, maxsize=1)
self.loop.create_task(q.put('a'))
self.loop.create_task(q.put('b'))
test_utils.run_briefly(self.loop)
Expand All @@ -298,8 +280,7 @@ async def producer(queue, num_items):
queue_size = 1
producer_num_items = 5

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(queue_size, loop=self.loop)
q = asyncio.Queue(queue_size, loop=self.loop)

self.loop.run_until_complete(
asyncio.gather(producer(q, producer_num_items),
Expand All @@ -320,17 +301,15 @@ async def consumer(queue):
except asyncio.TimeoutError:
pass

with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(loop=self.loop, maxsize=5)
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)


class QueuePutTests(_QueueTestBase):

def test_blocking_put(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q = asyncio.Queue(loop=self.loop)

async def queue_put():
# No maxsize, won't block.
Expand All @@ -347,9 +326,8 @@ def gen():

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, loop=loop)
started = asyncio.Event(loop=loop)
finished = False

async def queue_put():
Expand All @@ -371,8 +349,7 @@ async def queue_get():
self.assertAlmostEqual(0.01, loop.time())

def test_nonblocking_put(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=self.loop)
q = asyncio.Queue(loop=self.loop)
q.put_nowait(1)
self.assertEqual(1, q.get_nowait())

Expand All @@ -383,8 +360,7 @@ def gen():

loop = self.new_test_loop(gen)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
q = asyncio.Queue(loop=loop)

reader = loop.create_task(q.get())

Expand Down Expand Up @@ -413,8 +389,7 @@ def gen():
loop = self.new_test_loop(gen)
loop.set_debug(True)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(loop=loop)
q = asyncio.Queue(loop=loop)

reader1 = loop.create_task(q.get())
reader2 = loop.create_task(q.get())
Expand Down Expand Up @@ -444,8 +419,7 @@ def gen():

loop = self.new_test_loop(gen)

with self.assertWarns(DeprecationWarning):
q = asyncio.Queue(1, loop=loop)
q = asyncio.Queue(1, loop=loop)

q.put_nowait(1)

Expand All @@ -469,21 +443,18 @@ def gen():
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, 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 = 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)
q = asyncio.Queue(maxsize=1.3, loop=self.loop)

async def queue_put():
await q.put(1)
Expand All @@ -492,8 +463,7 @@ async def queue_put():
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(loop=self.loop)

async def queue_put():
await q.put(1)
Expand All @@ -508,8 +478,7 @@ async def test():
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(loop=self.loop, maxsize=1)

put_a = self.loop.create_task(q.put('a'))
put_b = self.loop.create_task(q.put('b'))
Expand All @@ -529,18 +498,15 @@ def test_put_cancelled_race(self):
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(loop=self.loop)
t = self.loop.create_task(q.get())
test_utils.run_briefly(self.loop)
self.loop.run_until_complete(q.put('a'))
self.assertEqual(self.loop.run_until_complete(t), 'a')

def test_why_are_putters_waiting(self):
# From issue #265.

with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(2, loop=self.loop)
queue = asyncio.Queue(2, loop=self.loop)

async def putter(item):
await queue.put(item)
Expand All @@ -566,8 +532,7 @@ def a_generator():
loop = self.new_test_loop(a_generator)

# Full queue.
with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(loop=loop, maxsize=1)
queue = asyncio.Queue(loop=loop, maxsize=1)
queue.put_nowait(1)

# Task waiting for space to put an item in the queue.
Expand All @@ -590,8 +555,7 @@ def gen():
loop = self.new_test_loop(gen)

# Full Queue.
with self.assertWarns(DeprecationWarning):
queue = asyncio.Queue(1, loop=loop)
queue = asyncio.Queue(1, loop=loop)
queue.put_nowait(1)

# Task waiting for space to put a item in the queue.
Expand All @@ -614,8 +578,7 @@ def gen():
class LifoQueueTests(_QueueTestBase):

def test_order(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.LifoQueue(loop=self.loop)
q = asyncio.LifoQueue(loop=self.loop)
for i in [1, 3, 2]:
q.put_nowait(i)

Expand All @@ -626,8 +589,7 @@ def test_order(self):
class PriorityQueueTests(_QueueTestBase):

def test_order(self):
with self.assertWarns(DeprecationWarning):
q = asyncio.PriorityQueue(loop=self.loop)
q = asyncio.PriorityQueue(loop=self.loop)
for i in [1, 3, 2]:
q.put_nowait(i)

Expand All @@ -640,13 +602,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(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)
q = self.q_class(loop=self.loop)
for i in range(100):
q.put_nowait(i)

Expand Down Expand Up @@ -681,8 +641,7 @@ async def test():
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(loop=self.loop)

# Test that a queue join()s successfully, and before anything else
# (done twice for insurance).
Expand All @@ -694,8 +653,7 @@ async def join():
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(loop=self.loop)
self.assertEqual(q._format(), 'maxsize=0')

q._unfinished_tasks = 2
Expand Down