MCPcopy Index your code
hub / github.com/python/cpython / _test_repr_or_str

Method _test_repr_or_str

Lib/test/test_asyncio/test_queues.py:14–54  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

12class 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)

Callers 2

test_reprMethod · 0.95
test_strMethod · 0.95

Calls 13

getMethod · 0.95
put_nowaitMethod · 0.95
putMethod · 0.95
get_nowaitMethod · 0.95
fnFunction · 0.85
idFunction · 0.85
QueueMethod · 0.80
assertStartsWithMethod · 0.80
assertTrueMethod · 0.80
assertEqualMethod · 0.45
create_taskMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected