diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-01-10 09:24:22 (GMT) |
---|---|---|
committer | Mark Shannon <mark@hotpy.org> | 2020-01-10 09:24:22 (GMT) |
commit | 4c53e63cc966f98e141a09bc435b9f9c713b152d (patch) | |
tree | 27435c8386cf6a99db3de9300b15a6ac6f70640d /Lib/test/test_sys_settrace.py | |
parent | 850a8856e120f8cba15e557a0e791f93b43d6989 (diff) | |
download | cpython-4c53e63cc966f98e141a09bc435b9f9c713b152d.zip cpython-4c53e63cc966f98e141a09bc435b9f9c713b152d.tar.gz cpython-4c53e63cc966f98e141a09bc435b9f9c713b152d.tar.bz2 |
bpo-39166: Fix trace of last iteration of async for loops (#17800)
Diffstat (limited to 'Lib/test/test_sys_settrace.py')
-rw-r--r-- | Lib/test/test_sys_settrace.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index a0d1122..bead57c 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -526,6 +526,82 @@ class TraceTestCase(unittest.TestCase): (7, 'line'), (7, 'return')]) + def test_20_async_for_loop(self): + class AsyncIteratorWrapper: + def __init__(self, obj): + self._it = iter(obj) + + def __aiter__(self): + return self + + async def __anext__(self): + try: + return next(self._it) + except StopIteration: + raise StopAsyncIteration + + async def doit_async(): + async for letter in AsyncIteratorWrapper("abc"): + x = letter + y = 42 + + def run(tracer): + x = doit_async() + try: + sys.settrace(tracer) + x.send(None) + finally: + sys.settrace(None) + + tracer = self.make_tracer() + events = [ + (0, 'call'), + (1, 'line'), + (-12, 'call'), + (-11, 'line'), + (-11, 'return'), + (-9, 'call'), + (-8, 'line'), + (-8, 'return'), + (-6, 'call'), + (-5, 'line'), + (-4, 'line'), + (-4, 'return'), + (1, 'exception'), + (2, 'line'), + (1, 'line'), + (-6, 'call'), + (-5, 'line'), + (-4, 'line'), + (-4, 'return'), + (1, 'exception'), + (2, 'line'), + (1, 'line'), + (-6, 'call'), + (-5, 'line'), + (-4, 'line'), + (-4, 'return'), + (1, 'exception'), + (2, 'line'), + (1, 'line'), + (-6, 'call'), + (-5, 'line'), + (-4, 'line'), + (-4, 'exception'), + (-3, 'line'), + (-2, 'line'), + (-2, 'exception'), + (-2, 'return'), + (1, 'exception'), + (3, 'line'), + (3, 'return')] + try: + run(tracer.trace) + except Exception: + pass + self.compare_events(doit_async.__code__.co_firstlineno, + tracer.events, events) + class SkipLineEventsTraceTestCase(TraceTestCase): """Repeat the trace tests, but with per-line events skipped""" |