pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/148702/files

"https://github.githubassets.com/assets/primer-primitives-7f694b60439d06c0.css" /> gh-148701: Add missing test coverage for asyncio.graph by ashm-dev · Pull Request #148702 · python/cpython · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions Lib/test/test_asyncio/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import io
import unittest
from unittest import mock


# To prevent a warning "test altered the execution environment"
Expand Down Expand Up @@ -345,6 +346,139 @@ async def main():

self.assertTrue(stack_for_fut[1].startswith('* Future(id='))

async def test_capture_call_graph_positive_limit(self):
captured = None

async def c3():
nonlocal captured
captured = asyncio.capture_call_graph(limit=2)

async def c2():
await c3()

async def c1():
await c2()

await c1()
self.assertEqual(len(captured.call_stack), 2)

async def test_capture_call_graph_negative_limit(self):
captured = None

async def c3():
nonlocal captured
captured = asyncio.capture_call_graph(limit=-2)

async def c2():
await c3()

async def c1():
await c2()

await c1()
self.assertEqual(len(captured.call_stack), 2)

async def test_capture_call_graph_zero_limit(self):
captured = None

async def inner():
nonlocal captured
captured = asyncio.capture_call_graph(limit=0)

await inner()
self.assertEqual(captured.call_stack, ())

def test_capture_call_graph_outside_loop(self):
with self.assertRaises(RuntimeError):
asyncio.capture_call_graph()

def test_capture_call_graph_non_future(self):
with self.assertRaises(TypeError):
asyncio.capture_call_graph("not a future")

async def test_capture_call_graph_no_current_task(self):
results = []

def cb():
results.append(asyncio.capture_call_graph())
results.append(asyncio.format_call_graph())

loop = asyncio.get_running_loop()
loop.call_soon(cb)
await asyncio.sleep(0)

self.assertEqual(results, [None, ""])

async def test_capture_call_graph_current_task_not_future(self):
sentinel = object()
with mock.patch('asyncio.tasks.current_task', return_value=sentinel):
with self.assertRaises(TypeError):
asyncio.capture_call_graph(sentinel)

async def test_build_graph_for_future_positive_limit(self):
fut = asyncio.Future()
captured = None

async def deep():
await fut

async def mid():
await deep()

async def runner():
await mid()

async def main():
nonlocal captured
async with asyncio.TaskGroup() as g:
t = g.create_task(runner(), name='runner')
for _ in range(5):
await asyncio.sleep(0)
Comment thread
kumaraditya303 marked this conversation as resolved.
captured = asyncio.capture_call_graph(t, limit=2)
fut.set_result(None)

await main()
self.assertEqual(len(captured.call_stack), 2)

async def test_build_graph_for_future_negative_limit(self):
fut = asyncio.Future()
captured = None

async def deep():
await fut

async def mid():
await deep()

async def runner():
await mid()

async def main():
nonlocal captured
async with asyncio.TaskGroup() as g:
t = g.create_task(runner(), name='runner')
for _ in range(5):
await asyncio.sleep(0)
captured = asyncio.capture_call_graph(t, limit=-2)
fut.set_result(None)

await main()
self.assertEqual(len(captured.call_stack), 2)

async def test_format_call_graph_regular_generator(self):
output = []

def gen():
output.append(asyncio.format_call_graph())
yield

async def main():
for _ in gen():
pass

await main()
self.assertRegex(output[0], r'in generator [\w.<>]+\.gen\(\)')


@unittest.skipIf(
not hasattr(asyncio.futures, "_c_future_add_to_awaited_by"),
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy