Test Queue's repr or str. fn is repr or str. expect_id is True if we expect the Queue's id to appear in fn(Queue()).
(self, fn, expect_id)
| 12 | class QueueBasicTests(unittest.IsolatedAsyncioTestCase): |
| 13 | |
| 14 | async def _test_repr_or_str(self, fn, expect_id): |
| 15 | """Test Queue's repr or str. |
| 16 | |
| 17 | fn is repr or str. expect_id is True if we expect the Queue's id to |
| 18 | appear in fn(Queue()). |
| 19 | """ |
| 20 | q = asyncio.Queue() |
| 21 | self.assertStartsWith(fn(q), '<Queue') |
| 22 | id_is_present = hex(id(q)) in fn(q) |
| 23 | self.assertEqual(expect_id, id_is_present) |
| 24 | |
| 25 | # getters |
| 26 | q = asyncio.Queue() |
| 27 | async with asyncio.TaskGroup() as tg: |
| 28 | # Start a task that waits to get. |
| 29 | getter = tg.create_task(q.get()) |
| 30 | # Let it start waiting. |
| 31 | await asyncio.sleep(0) |
| 32 | self.assertTrue('_getters[1]' in fn(q)) |
| 33 | # resume q.get coroutine to finish generator |
| 34 | q.put_nowait(0) |
| 35 | |
| 36 | self.assertEqual(0, await getter) |
| 37 | |
| 38 | # putters |
| 39 | q = asyncio.Queue(maxsize=1) |
| 40 | async with asyncio.TaskGroup() as tg: |
| 41 | q.put_nowait(1) |
| 42 | # Start a task that waits to put. |
| 43 | putter = tg.create_task(q.put(2)) |
| 44 | # Let it start waiting. |
| 45 | await asyncio.sleep(0) |
| 46 | self.assertTrue('_putters[1]' in fn(q)) |
| 47 | # resume q.put coroutine to finish generator |
| 48 | q.get_nowait() |
| 49 | |
| 50 | self.assertTrue(putter.done()) |
| 51 | |
| 52 | q = asyncio.Queue() |
| 53 | q.put_nowait(1) |
| 54 | self.assertTrue('_queue=[1]' in fn(q)) |
| 55 | |
| 56 | async def test_repr(self): |
| 57 | await self._test_repr_or_str(repr, True) |
no test coverage detected