Debian Codegraph @

lib-python/3/test/test_asyncio/test_futures2.py

raw symbols SCIP
1 # IsolatedAsyncioTestCase based tests
2 import asyncio
3 import traceback
4 import unittest
5 from asyncio import tasks
6
7
8 def tearDownModule():
9 asyncio.set_event_loop_policy(None)
10
11
12 class FutureTests:
13
14 async def test_future_traceback(self):
15
16 async def raise_exc():
17 raise TypeError(42)
18
19 future = self.cls(raise_exc())
20
21 for _ in range(5):
22 try:
23 await future
24 except TypeError as e:
25 tb = ''.join(traceback.format_tb(e.__traceback__))
26 self.assertEqual(tb.count("await future"), 1)
27 else:
28 self.fail('TypeError was not raised')
29
30 @unittest.skipUnless(hasattr(tasks, '_CTask'),
31 'requires the C _asyncio module')
32 class CFutureTests(FutureTests, unittest.IsolatedAsyncioTestCase):
33 try:
34 cls = tasks._CTask
35 except AttributeError:
36 cls = tasks._PyTask
37
38 class PyFutureTests(FutureTests, unittest.IsolatedAsyncioTestCase):
39 cls = tasks._PyTask
40
41 class FutureReprTests(unittest.IsolatedAsyncioTestCase):
42
43 async def test_recursive_repr_for_pending_tasks(self):
44 # The call crashes if the guard for recursive call
45 # in base_futures:_future_repr_info is absent
46 # See Also: https://bugs.python.org/issue42183
47
48 async def func():
49 return asyncio.all_tasks()
50
51 # The repr() call should not raise RecursiveError at first.
52 # The check for returned string is not very reliable but
53 # exact comparison for the whole string is even weaker.
54 self.assertIn('...', repr(await asyncio.wait_for(func(), timeout=10)))
55
56
57 if __name__ == '__main__':
58 unittest.main()