a
    3j                     @   s,  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ G dd dZG dd dZdd	 Zd
d Ze jdd ZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZe	jG dd dejZedkr(e  dS )    N)supportassert_python_okc                   @   s   e Zd Zdd Zdd ZdS )AsyncYieldFromc                 C   s
   || _ d S Nobj)selfr    r
   P/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_coroutines.py__init__   s    zAsyncYieldFrom.__init__c                 c   s   | j E d H  d S r   r   r	   r
   r
   r   	__await__   s    zAsyncYieldFrom.__await__N__name__
__module____qualname__r   r   r
   r
   r
   r   r      s   r   c                   @   s   e Zd Zdd Zdd ZdS )
AsyncYieldc                 C   s
   || _ d S r   value)r	   r   r
   r
   r   r      s    zAsyncYield.__init__c                 c   s   | j V  d S r   r   r   r
   r
   r   r      s    zAsyncYield.__await__Nr   r
   r
   r
   r   r      s   r   c              
   C   sl   g }d }z| | d  W q ty` } z,|jr<|jd nd }W Y d }~qdW Y d }~qd }~0 0 q||fS Nr   )appendsendStopIterationargs)corobufferresultexr
   r
   r   	run_async   s    $r   c              
   C   s   |   }g }d }d}z4|d r.|t| n||d  |d7 }W q ty } z,|jrh|jd nd }W Y d }~qW Y d }~qd }~0 0 q||fS )Nr         )r   r   nextr   r   r   )r   awr   r   ir   r
   r
   r   run_async__await__+   s    $r%   c                   c   sD   t  ( t d d V  t  W d    n1 s60    Y  d S )Nignore)warningscatch_warningssimplefilterr   
gc_collectr
   r
   r
   r   silence_coro_gc>   s    

r+   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
AsyncBadSyntaxTestc              
   C   sx   g d}|D ]f}| j |dF | t t|dd W d    n1 sJ0    Y  W d    q1 sh0    Y  qd S )N);z9def foo():
                await something()
            zawait something()z;async def foo():
                yield from []
            z=async def foo():
                await await fut
            zEasync def foo(a=await something()):
                pass
            zEasync def foo(a:await something()):
                pass
            z`async def foo():
                def bar():
                 [i async for i in els]
            z`async def foo():
                def bar():
                 [await i for i in els]
            zasync def foo():
                def bar():
                 [i for i in els
                    async for b in els]
            zasync def foo():
                def bar():
                 [i for i in els
                    for c in b
                    async for b in els]
            zasync def foo():
                def bar():
                 [i for i in els
                    async for b in els
                    for c in b]
            zasync def foo():
                def bar():
                 [i for i in els
                    for b in await els]
            zasync def foo():
                def bar():
                 [i for i in els
                    for b in els
                        if await b]
            z`async def foo():
                def bar():
                 [i for i in await els]
            zeasync def foo():
                def bar():
                 [i for i in els if await i]
            z?def bar():
                 [i async for i in els]
            zBdef bar():
                 {i: i async for i in els}
            z?def bar():
                 {i async for i in els}
            z?def bar():
                 [await i for i in els]
            z`def bar():
                 [i for i in els
                    async for b in els]
            zdef bar():
                 [i for i in els
                    for c in b
                    async for b in els]
            zdef bar():
                 [i for i in els
                    async for b in els
                    for c in b]
            z`def bar():
                 [i for i in els
                    for b in await els]
            z}def bar():
                 [i for i in els
                    for b in els
                        if await b]
            z?def bar():
                 [i for i in await els]
            zDdef bar():
                 [i for i in els if await i]
            z3async def foo():
                await
            z]async def foo():
                   def bar(): pass
                   await = 1
            z^async def foo():

                   def bar(): pass
                   await = 1
            zzasync def foo():
                   def bar(): pass
                   if 1:
                       await = 1
            zxdef foo():
                   async def bar(): pass
                   if 1:
                       await a
            z[def foo():
                   async def bar(): pass
                   await a
            z~def foo():
                   def baz(): pass
                   async def bar(): pass
                   await a
            zdef foo():
                   def baz(): pass
                   # 456
                   async def bar(): pass
                   # 123
                   await a
            zasync def foo():
                   def baz(): pass
                   # 456
                   async def bar(): pass
                   # 123
                   await = 2
            zdef foo():

                   def baz(): pass

                   async def bar(): pass

                   await a
            zasync def foo():

                   def baz(): pass

                   async def bar(): pass

                   await = 2
            zBasync def foo():
                   def async(): pass
            zBasync def foo():
                   def await(): pass
            zXasync def foo():
                   def bar():
                       await
            zKasync def foo():
                   return lambda async: await
            zGasync def foo():
                   return lambda a: await
            z	await a()z>async def foo(a=await b):
                   pass
            z>async def foo(a:await b):
                   pass
            z`def baz():
                   async def foo(a=await b):
                       pass
            z:async def foo(async):
                   pass
            zasync def foo():
                   def bar():
                        def baz():
                            async = 1
            zasync def foo():
                   def bar():
                        def baz():
                            pass
                        async = 1
            zdef foo():
                   async def bar():

                        async def baz():
                            pass

                        def baz():
                            42

                        async = 1
            zasync def foo():
                   def bar():
                        def baz():
                            pass
await foo()
            zdef foo():
                   def bar():
                        async def baz():
                            pass
await foo()
            z:async def foo(await):
                   pass
            z]def foo():

                   async def bar(): pass

                   await a
            z`def foo():
                   async def bar():
                        pass
await a
            z`def foo():
                   async for i in arange(2):
                       pass
            z[def foo():
                   async with resource:
                       pass
            z9async with resource:
                   pass
            z>async for i in arange(2):
                   pass
            code<test>execZsubTestassertRaisesSyntaxErrorcompiler	   Zsamplesr.   r
   r
   r   test_badsyntax_1H   s      6z#AsyncBadSyntaxTest.test_badsyntax_1c              
   C   sx   g d}|D ]f}| j |dF | t t|dd W d    n1 sJ0    Y  W d    q1 sh0    Y  qd S )N)	z1def foo():
                await = 1
            z9class Bar:
                def async(): pass
            z1class Bar:
                async = 1
            z.class async:
                pass
            z.class await:
                pass
            zimport math as awaitz!def async():
                passz2def foo(*, await=1):
                passasync = 1zprint(await=1)r-   r/   r0   r1   r5   r
   r
   r   test_badsyntax_2  s    "z#AsyncBadSyntaxTest.test_badsyntax_2c                 C   s:   |  t tddd W d    n1 s,0    Y  d S )Nz	async = 1r/   r0   )r2   r3   r4   r   r
   r
   r   test_badsyntax_3  s    z#AsyncBadSyntaxTest.test_badsyntax_3c              
   C   sx   g d}|D ]f}| j |dF | t t|dd W d    n1 sJ0    Y  W d    q1 sh0    Y  qd S )N)zdef foo(await):
                async def foo(): pass
                async def foo():
                    pass
                return await + 1
            zdef foo(await):
                async def foo(): pass
                async def foo(): pass
                return await + 1
            zdef foo(await):

                async def foo(): pass

                async def foo(): pass

                return await + 1
            zdef foo(await):
                """spam"""
                async def foo():                     pass
                # 123
                async def foo(): pass
                # 456
                return await + 1
            a:  def foo(await):
                def foo(): pass
                def foo(): pass
                async def bar(): return await_
                await_ = await
                try:
                    bar().send(None)
                except StopIteration as ex:
                    return ex.args[0] + 1
            r-   r/   r0   r1   r5   r
   r
   r   test_badsyntax_4  s    -z#AsyncBadSyntaxTest.test_badsyntax_4N)r   r   r   r6   r7   r8   r9   r
   r
   r
   r   r,   F   s     ;'r,   c                   @   s   e Zd Zdd ZdS )TokenizerRegrTestc                 C   s   g }t dD ]}|dj|d qd|}i }t||| | |d  d |d7 }i }t||| | |d  d | t|d  d S )	Ni  zdef i{i}(): return {i}r$   
Zi499i  z
async def foo():
    returnfoo)	ranger   formatjoinr0   assertEqual
assertTrueinspectZiscoroutinefunction)r	   bufr$   nsr
   r
   r   test_oneline_defs  s    
z#TokenizerRegrTest.test_oneline_defsN)r   r   r   rF   r
   r
   r
   r   r:     s   r:   c                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkdl Z8dmdn Z9dodp Z:dqdr Z;dsdt Z<dudv Z=dwdx Z>dydz Z?d{d| Z@d}d~ ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdS )CoroutineTestc                 C   s   dd }|  t|d d S )Nc                   s   s
   d V  d S r   r
   r
   r
   r
   r   gen      z%CoroutineTest.test_gen_1.<locals>.genr   )assertFalsehasattr)r	   rH   r
   r
   r   
test_gen_1  s    zCoroutineTest.test_gen_1c                 C   s   dd }| }|  |tj | t|jjtj@  | 	t|jjtj
@  | t|jjtj@  | 	t|jjtj
@  | t|g df | t| g df dd }| 	t|jjtj@  d S )Nc                      s   dS N
   r
   r
   r
   r
   r   r=     s    z&CoroutineTest.test_func_1.<locals>.foorN   c                   S   s   d S r   r
   r
   r
   r
   r   bar	  rI   z&CoroutineTest.test_func_1.<locals>.bar)assertIsInstancetypesCoroutineTyperB   bool__code__co_flagsrC   ZCO_COROUTINErJ   ZCO_GENERATORcr_coderA   r   r%   )r	   r=   frO   r
   r
   r   test_func_1  s    zCoroutineTest.test_func_1c                 C   sB   dd }|  td t|  W d    n1 s40    Y  d S )Nc                      s   t d S r   r   r
   r
   r
   r   r=     s    z&CoroutineTest.test_func_2.<locals>.foozcoroutine raised StopIteration)assertRaisesRegexRuntimeErrorr   r	   r=   r
   r
   r   test_func_2  s
    zCoroutineTest.test_func_2c                 C   s*   dd }| }|  t|d |  d S )Nc                      s   t d S r   rY   r
   r
   r
   r   r=     s    z&CoroutineTest.test_func_3.<locals>.fooz^<coroutine object.* at 0x.*>$)assertRegexreprclose)r	   r=   r   r
   r
   r   test_func_3  s    zCoroutineTest.test_func_3c                    sD  dd }| } fdd}|  t | W d    n1 s>0    Y  |  t| W d    n1 sl0    Y  |  t| W d    n1 s0    Y  |  t| W d    n1 s0    Y  |  |D ]}qW d    n1 s0    Y  |  dd |D  W d    n1 s.0    Y  |  d S )Nc                      s   t d S r   rY   r
   r
   r
   r   r=     s    z&CoroutineTest.test_func_4.<locals>.fooc                      s     tdS Nz"'coroutine' object is not iterablerZ   	TypeErrorr
   r   r
   r   <lambda>"  s   z+CoroutineTest.test_func_4.<locals>.<lambda>c                 S   s   g | ]}|qS r
   r
   .0r$   r
   r
   r   
<listcomp>6  rI   z-CoroutineTest.test_func_4.<locals>.<listcomp>)listtuplesumiterr`   )r	   r=   r   checkr$   r
   r   r   test_func_4  s"    &&&& .zCoroutineTest.test_func_4c                    s   t jdd   fdd}fdd}| }|  |D ]}q8W d    n1 sR0    Y  |    D ]}|d qjdd	   D dg t  d
 tt  d d S )Nc                   s   s
   dV  d S Nr!   r
   r
   r
   r
   r   rO   ;  s    z&CoroutineTest.test_func_5.<locals>.barc                      s     I d H  d S r   r
   r
   rO   r
   r   r=   ?  s    z&CoroutineTest.test_func_5.<locals>.fooc                      s     tdS rb   rc   r
   r   r
   r   re   B  s   z+CoroutineTest.test_func_5.<locals>.<lambda>r!   c                 S   s   g | ]}|qS r
   r
   )rg   elr
   r
   r   rh   N  rI   z-CoroutineTest.test_func_5.<locals>.<listcomp>)r!   )rQ   	coroutiner`   rA   rj   r"   rl   )r	   r=   rm   r   rq   r
   )rO   r	   r   test_func_5:  s    
 
zCoroutineTest.test_func_5c                    s|   t jdd   fdd}| }| |d d | |d d | t |d  W d    n1 sn0    Y  d S )Nc                   s   s   dV  dV  d S Nr!   r    r
   r
   r
   r
   r   rO   S  s    z&CoroutineTest.test_func_6.<locals>.barc                      s     I d H  d S r   r
   r
   rp   r
   r   r=   X  s    z&CoroutineTest.test_func_6.<locals>.foor!   r    )rQ   rr   rA   r   r2   r   )r	   r=   rW   r
   rp   r   test_func_6R  s    
zCoroutineTest.test_func_6c                    s\   dd }|   fdd}|  td t|  W d    n1 sF0    Y     d S )Nc                      s   dS rM   r
   r
   r
   r
   r   rO   b  s    z&CoroutineTest.test_func_7.<locals>.barc                   3   s    E d H  d S r   r
   r
   r   r
   r   r=   f  s    z&CoroutineTest.test_func_7.<locals>.foozCcannot 'yield from' a coroutine object in a non-coroutine generator)rZ   rd   ri   r`   r	   rO   r=   r
   rv   r   test_func_7a  s    (zCoroutineTest.test_func_7c                    sB   t j fdd}dd }|  | t| g df    d S )Nc                   3   s
    E d H S r   r
   r
   rv   r
   r   rO   r  s    z&CoroutineTest.test_func_8.<locals>.barc                      s   dS Nspamr
   r
   r
   r
   r   r=   v  s    z&CoroutineTest.test_func_8.<locals>.foorz   )rQ   rr   rA   r   r`   rw   r
   rv   r   test_func_8q  s    zCoroutineTest.test_func_8c              	   C   s   dd }|  td |  t  W d    n1 s80    Y  |  tdN | t | D ]}qbW d    n1 s|0    Y  t  W d    n1 s0    Y  d S )Nc                      s   d S r   r
   r
   r
   r
   r   r=   ~  s    z&CoroutineTest.test_func_9.<locals>.fooz0coroutine '.*test_func_9.*foo' was never awaited)ZassertWarnsRegexRuntimeWarningr   r*   r2   rd   )r	   r=   _r
   r
   r   test_func_9}  s    &
 zCoroutineTest.test_func_9c                    s   d t j fddfdd}| }| }| |t| t| | |dd |  d |  |  d | }| }t| | 	t
 |t
d d  W d    n1 s0    Y  |  d	 d S )
Nr   c                  3   sN   z>zd V } | d V  W n t y2    d7   Y n0 W  d7  n
 d7  0 d S )Nr    d   r!   ZeroDivisionErrora)Nr
   r   rH     s    
z'CoroutineTest.test_func_10.<locals>.genc                      s     I d H  d S r   r
   r
   rH   r
   r   r=     s    z'CoroutineTest.test_func_10.<locals>.foorN   r   r!   f   )rQ   rr   r   assertIsrl   r"   rA   r   r`   r2   r   throw)r	   r=   r   r#   r
   )r   rH   r   test_func_10  s$    ,zCoroutineTest.test_func_10c                 C   sR   dd }| }|  dt| |  dt|  |  dt|  |  d S )Nc                      s   d S r   r
   r
   r
   r
   r   func  rI   z(CoroutineTest.test_func_11.<locals>.funcr   __iter__Zcoroutine_wrapper)assertIndirr   r_   r`   )r	   r   r   r
   r
   r   test_func_11  s    zCoroutineTest.test_func_11c                    sL    fdd}|  |  td  d  W d    n1 s>0    Y  d S )Nc                     s     d } tI d H  d S r   )r   r=   r;   mer
   r   g  s    
z%CoroutineTest.test_func_12.<locals>.gzcoroutine already executing)rZ   
ValueErrorr   )r	   r   r
   r   r   test_func_12  s    zCoroutineTest.test_func_12c                 C   sP   dd }| }|  td |d W d    n1 s:0    Y  |  d S )Nc                      s   d S r   r
   r
   r
   r
   r   r     s    z%CoroutineTest.test_func_13.<locals>.gz5can't send non-None value to a just-started coroutinerz   )rZ   rd   r   r`   )r	   r   r   r
   r
   r   test_func_13  s    (zCoroutineTest.test_func_13c                    sb   t jdd   fdd}| }|d  | td |  W d    n1 sT0    Y  d S )Nc                   s   s
   d V  d S r   r
   r
   r
   r
   r   rH     s    z'CoroutineTest.test_func_14.<locals>.genc                      s4   z  I d H  W n t y.     I d H  Y n0 d S r   GeneratorExitr
   r   r
   r   r     s    z(CoroutineTest.test_func_14.<locals>.corozcoroutine ignored GeneratorExit)rQ   rr   r   rZ   r[   r`   )r	   r   cr
   r   r   test_func_14  s    

zCoroutineTest.test_func_14c                 C   s   dd }dd }| }|  td ||d  W d    n1 sF0    Y  |  td ||d  W d    n1 s0    Y  d S )Nc                      s   dS ry   r
   r
   r
   r
   r   spammer  s    z+CoroutineTest.test_func_15.<locals>.spammerc                    s
   | I d H S r   r
   rv   r
   r
   r   reader  s    z*CoroutineTest.test_func_15.<locals>.readerrz   &cannot reuse already awaited coroutine)rZ   r   r   r[   )r	   r   r   Zspammer_coror
   r
   r   test_func_15  s    ,zCoroutineTest.test_func_15c                    s  t jdd   fdd} fdd}| }||}|d  |d  | td |td W d    n1 sx0    Y  ||}|d  | td |d  W d    n1 s0    Y  | td |td	 W d    n1 s0    Y  d S )
Nc                   s   s
   d V  d S r   r
   r
   r
   r
   r   nop  s    z'CoroutineTest.test_func_16.<locals>.nopc                      s     I d H  dS ry   r
   r
   r   r
   r   r     s    z(CoroutineTest.test_func_16.<locals>.sendc                    s     I d H  | I d H S r   r
   rv   r   r
   r   read  s    z(CoroutineTest.test_func_16.<locals>.readhamr   wat)rQ   rr   r   rZ   	Exceptionr   r[   )r	   r   r   r   r   r
   r   r   test_func_16  s(    


,
(zCoroutineTest.test_func_16c                 C   s   dd }| }|  td |d  W d    n1 s:0    Y  |  td |d  W d    n1 sp0    Y  |  td |td W d    n1 s0    Y  |  |  d S )Nc                      s   dS ry   r
   r
   r
   r
   r   rr     s    z-CoroutineTest.test_func_17.<locals>.coroutinerz   r   r   )rZ   r   r   r[   r   r   r`   )r	   rr   r   r
   r
   r   test_func_17  s    ((,zCoroutineTest.test_func_17c                 C   sH  dd }| }|  }t|}| td |d  W d    n1 sJ0    Y  | td |d  W d    n1 s0    Y  | td t| W d    n1 s0    Y  | td |td W d    n1 s0    Y  | td |td W d    n1 s*0    Y  |	  |	  d S )Nc                      s   dS ry   r
   r
   r
   r
   r   rr   .  s    z-CoroutineTest.test_func_18.<locals>.coroutinerz   r   r   )
r   rl   rZ   r   r   r[   r"   r   r   r`   )r	   rr   r   Z
await_iteritr
   r
   r   test_func_18+  s0    ((&,.zCoroutineTest.test_func_18c                    s   d t j fddfdd}| }|d  |d  |  d |  |  d tdD ]}|  |  d qdd S )Nr   c                   3   s0   d V  z
d V  W n t y*    d7  Y n0 d S ro   r   r
   )CHKr
   r   r=   V  s
    
z'CoroutineTest.test_func_19.<locals>.fooc                      s     I d H  d S r   r
   r
   )r=   r
   r   rr   _  s    z-CoroutineTest.test_func_19.<locals>.coroutiner!      )rQ   rr   r   rA   r`   r>   )r	   rr   r   r}   r
   )r   r=   r   test_func_19S  s    

zCoroutineTest.test_func_19c                 C   s&   dd }t | }| |g df d S )Nc                      s   dS )NrN   r
   r
   r
   r
   r   r=   r  s    z7CoroutineTest.test_coro_wrapper_send_tuple.<locals>.foor   )r%   rA   r	   r=   r   r
   r
   r   test_coro_wrapper_send_tupleq  s    
z*CoroutineTest.test_coro_wrapper_send_tuplec                 C   s8   dd }t | }| |d t | |d jd d S )Nc                      s   t dS rM   rY   r
   r
   r
   r   r=   y  s    z?CoroutineTest.test_coro_wrapper_send_stop_iterator.<locals>.foor!   rN   )r%   rP   r   rA   r   r   r
   r
   r   $test_coro_wrapper_send_stop_iteratorx  s    
z2CoroutineTest.test_coro_wrapper_send_stop_iteratorc                    s   t jfdd  fddfdd}| ttj j d  ttj	 jjj
jd t d  W d    n1 s0    Y  ttj j d S )Nc                   3   sJ    t tj  j d V   t tj  j d S r   )rA   rC   getcoroutinestateZCORO_RUNNINGassertIsNonecr_awaitr
   )coro_br	   r
   r   r     s
    z&CoroutineTest.test_cr_await.<locals>.ac                      s     I d H  d S r   r
   r
   r   r
   r   r     s    z&CoroutineTest.test_cr_await.<locals>.cc                      s(    j   I d H   j d S r   )r   r   r
   )r   r   r	   r
   r   b  s    z&CoroutineTest.test_cr_await.<locals>.br   )rQ   rr   rA   rC   r   ZCORO_CREATEDr   r   r   ZCORO_SUSPENDEDgi_codeco_namer2   r   ZCORO_CLOSED)r	   r   r
   )r   r   r   r	   r   test_cr_await  s    
(zCoroutineTest.test_cr_awaitc                 C   s   t j}| d|jj | d|jj | d|jj | d|jd j | d|jd j | |j	d dd	 }| }| d
t
| |  d S )Nzinto coroutinezinside coroutinezin coroutinezof the coroutiner   r   rr   c                      s   d S r   r
   r
   r
   r
   r   rW     rI   z(CoroutineTest.test_corotype_1.<locals>.fzcoroutine object)rQ   rR   r   r   __doc__r`   r   __dict__rA   r   r_   )r	   ctrW   r   r
   r
   r   test_corotype_1  s    zCoroutineTest.test_corotype_1c                 C   sB   dd }|  td t|  W d    n1 s40    Y  d S )Nc                      s   dI d H  d S ro   r
   r
   r
   r
   r   r=     s    z'CoroutineTest.test_await_1.<locals>.foozobject int can.t.*awaitrZ   rd   r   r\   r
   r
   r   test_await_1  s    zCoroutineTest.test_await_1c                 C   sB   dd }|  td t|  W d    n1 s40    Y  d S )Nc                      s   g I d H  d S r   r
   r
   r
   r
   r   r=     s    z'CoroutineTest.test_await_2.<locals>.foozobject list can.t.*awaitr   r\   r
   r
   r   test_await_2  s    zCoroutineTest.test_await_2c                 C   s@   dd }|  t| g dd f |  t| g dd f d S )Nc                      s   t g dI d H  d S )Nr!   r    r   )r   r
   r
   r
   r   r=     s    z'CoroutineTest.test_await_3.<locals>.foor   )rA   r   r%   r\   r
   r
   r   test_await_3  s    zCoroutineTest.test_await_3c                    s.   dd   fdd}|  t| g df d S )Nc                      s   dS N*   r
   r
   r
   r
   r   rO     s    z'CoroutineTest.test_await_4.<locals>.barc                      s     I d H S r   r
   r
   rp   r
   r   r=     s    z'CoroutineTest.test_await_4.<locals>.foor   rA   r   r\   r
   rp   r   test_await_4  s    zCoroutineTest.test_await_4c                    sT   G dd d  fdd}|  td t|  W d    n1 sF0    Y  d S )Nc                   @   s   e Zd Zdd ZdS )z-CoroutineTest.test_await_5.<locals>.Awaitablec                 S   s   d S r   r
   r   r
   r
   r   r     s    z7CoroutineTest.test_await_5.<locals>.Awaitable.__await__Nr   r   r   r   r
   r
   r
   r   	Awaitable  s   r   c                      s     I d H S r   r
   r
   r   r
   r   r=     s    z'CoroutineTest.test_await_5.<locals>.foo(__await__.*returned non-iterator of typer   r\   r
   r   r   test_await_5  s    zCoroutineTest.test_await_5c                    s6   G dd d  fdd}|  t| dgd f d S )Nc                   @   s   e Zd Zdd ZdS )z-CoroutineTest.test_await_6.<locals>.Awaitablec                 S   s
   t dgS )N4   rl   r   r
   r
   r   r     s    z7CoroutineTest.test_await_6.<locals>.Awaitable.__await__Nr   r
   r
   r
   r   r     s   r   c                      s     I d H S r   r
   r
   r   r
   r   r=     s    z'CoroutineTest.test_await_6.<locals>.foor   r   r\   r
   r   r   test_await_6  s    zCoroutineTest.test_await_6c                    s6   G dd d  fdd}|  t| dgdf d S )Nc                   @   s   e Zd Zdd ZdS )z-CoroutineTest.test_await_7.<locals>.Awaitablec                 s   s
   dV  dS )Nr   r   r
   r   r
   r
   r   r     s    z7CoroutineTest.test_await_7.<locals>.Awaitable.__await__Nr   r
   r
   r
   r   r     s   r   c                      s     I d H S r   r
   r
   r   r
   r   r=     s    z'CoroutineTest.test_await_7.<locals>.foor   r   r   r\   r
   r   r   test_await_7  s    zCoroutineTest.test_await_7c                    sT   G dd d  fdd}|  td t|  W d    n1 sF0    Y  d S )Nc                   @   s   e Zd ZdS )z-CoroutineTest.test_await_8.<locals>.AwaitableNr   r   r   r
   r
   r
   r   r     s   r   c                      s     I d H S r   r
   r
   r   r
   r   r=     rI   z'CoroutineTest.test_await_8.<locals>.fooz4object Awaitable can't be used in 'await' expressionr   r\   r
   r   r   test_await_8  s    zCoroutineTest.test_await_8c                    s^    fdddd   fdd} fdd}|  t| g d	f |  t| g d
f d S )Nc                      s    S r   r
   r
   rp   r
   r   wrap  s    z(CoroutineTest.test_await_9.<locals>.wrapc                      s   dS r   r
   r
   r
   r
   r   rO     s    z'CoroutineTest.test_await_9.<locals>.barc                     sp   dfddi} G fddd}  I d H   I d H  | d    I d H    I d H d  |   I d H  S )Nr   c                      s    S r   r
   r
   r   r
   r   re     rI   z9CoroutineTest.test_await_9.<locals>.foo.<locals>.<lambda>c                       s   e Zd Z ZdS )z3CoroutineTest.test_await_9.<locals>.foo.<locals>.DBN)r   r   r   r   r
   r   r
   r   DB   s   r     )r   )Zdbr   rO   r   r
   r   r=     s    ,z'CoroutineTest.test_await_9.<locals>.fooc                      s     I d H  S r   r
   r
   rp   r
   r   foo2  s    z(CoroutineTest.test_await_9.<locals>.foo2i  ir   r	   r=   r   r
   r   r   test_await_9  s    	zCoroutineTest.test_await_9c                    s:   dd fdd  fdd}|  t| g df d S )Nc                      s   dS r   r
   r
   r
   r
   r   baz  s    z(CoroutineTest.test_await_10.<locals>.bazc                      s     S r   r
   r
   )r   r
   r   rO     s    z(CoroutineTest.test_await_10.<locals>.barc                      s     I d H I d H S r   r
   r
   rp   r
   r   r=     s    z(CoroutineTest.test_await_10.<locals>.foor   r   r\   r
   )rO   r   r   test_await_10  s    zCoroutineTest.test_await_10c                    sD   dd dd   fdd} fdd}|  t| g d	f d S )
Nc                 S   s   | S r   r
   valr
   r
   r   ident  s    z*CoroutineTest.test_await_11.<locals>.identc                      s   dS ry   r
   r
   r
   r
   r   rO     s    z(CoroutineTest.test_await_11.<locals>.barc                      s     I d H dS )Nr   r
   r
   rO   r   r
   r   r=     s    z(CoroutineTest.test_await_11.<locals>.fooc                      s     I d H dfS )Nr   r
   r
   rp   r
   r   r   "  s    z)CoroutineTest.test_await_11.<locals>.foo2)rz   r   r   r   r
   r   r   test_await_11  s
    zCoroutineTest.test_await_11c                    sn   dd }| G fddd  fdd}|  td t|  W d    n1 sX0    Y    d S )Nc                      s   dS ry   r
   r
   r
   r
   r   r   (  s    z)CoroutineTest.test_await_12.<locals>.coroc                       s   e Zd Z fddZdS )z.CoroutineTest.test_await_12.<locals>.Awaitablec                    s    S r   r
   r   r   r
   r   r   -  s    z8CoroutineTest.test_await_12.<locals>.Awaitable.__await__Nr   r
   r   r
   r   r   ,  s   r   c                      s     I d H S r   r
   r
   r   r
   r   r=   0  s    z(CoroutineTest.test_await_12.<locals>.fooz"__await__\(\) returned a coroutine)rZ   rd   r   r`   )r	   r   r=   r
   )r   r   r   test_await_12'  s    (zCoroutineTest.test_await_12c                    sT   G dd d  fdd}|  td t|  W d    n1 sF0    Y  d S )Nc                   @   s   e Zd Zdd ZdS )z.CoroutineTest.test_await_13.<locals>.Awaitablec                 S   s   | S r   r
   r   r
   r
   r   r   ;  s    z8CoroutineTest.test_await_13.<locals>.Awaitable.__await__Nr   r
   r
   r
   r   r   :  s   r   c                      s     I d H S r   r
   r
   r   r
   r   r=   >  s    z(CoroutineTest.test_await_13.<locals>.foor   r   r\   r
   r   r   test_await_139  s    zCoroutineTest.test_await_13c                    s   G dd dG dd d G dd dt  fddfd	d
}| }|d  | td |d W d    n1 s0    Y  | }|d  |  |t W d    n1 s0    Y  d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z,CoroutineTest.test_await_14.<locals>.Wrapperc                 S   s
   || _ d S r   rv   )r	   r   r
   r
   r   r   I  s    z5CoroutineTest.test_await_14.<locals>.Wrapper.__init__c                 S   s
   | j  S r   )r   r   r   r
   r
   r   r   L  s    z6CoroutineTest.test_await_14.<locals>.Wrapper.__await__Nr   r
   r
   r
   r   WrapperG  s   r   c                   @   s   e Zd Zdd ZdS )z/CoroutineTest.test_await_14.<locals>.FutureLikec                 s   s   d V S r   r
   r   r
   r
   r   r   P  s    z9CoroutineTest.test_await_14.<locals>.FutureLike.__await__Nr   r
   r
   r
   r   
FutureLikeO  s   r   c                   @   s   e Zd ZdS )z+CoroutineTest.test_await_14.<locals>.MarkerNr   r
   r
   r
   r   MarkerS  s   r   c                      s*   z  I d H W S  t y$   Y n0 d S r   r   r
   )r   r   r
   r   coro1V  s    z*CoroutineTest.test_await_14.<locals>.coro1c                      s     I d H S r   r
   r
   )r   r   r
   r   coro2[  s    z*CoroutineTest.test_await_14.<locals>.coro2rz   )r   r   rZ   r   r2   r   r   )r	   r   r   r
   )r   r   r   r   r   test_await_14F  s    
(
zCoroutineTest.test_await_14c                    sp   t jdd   fdd}dd }| }|d  | td ||d  W d    n1 sb0    Y  d S )Nc                   s   s
   d V  d S r   r
   r
   r
   r
   r   r   i  s    z(CoroutineTest.test_await_15.<locals>.nopc                      s     I d H  d S r   r
   r
   r   r
   r   rr   m  s    z.CoroutineTest.test_await_15.<locals>.coroutinec                    s   | I d H  d S r   r
   rv   r
   r
   r   waiterp  s    z+CoroutineTest.test_await_15.<locals>.waiterz"coroutine is being awaited already)rQ   rr   r   rZ   r[   )r	   rr   r   r   r
   r   r   test_await_15h  s    

zCoroutineTest.test_await_15c                    s2   dd   fdd}t | \}}| |j d S )Nc                      s   t  S r   )r   r
   r
   r
   r   rW   }  s    z&CoroutineTest.test_await_16.<locals>.fc                      s&   zt W n     I d H  Y S 0 d S r   )KeyErrorr
   rW   r
   r   r     s    z&CoroutineTest.test_await_16.<locals>.g)r   r   __context__)r	   r   r}   r   r
   r   r   test_await_16z  s    zCoroutineTest.test_await_16c                    s   G dd d  fdd}| }t |\}}| |g d  fdd}| t t |  W d    n1 sr0    Y  d S )Nc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z*CoroutineTest.test_with_1.<locals>.Managerc                 S   s
   || _ d S r   )name)r	   r   r
   r
   r   r     s    z3CoroutineTest.test_with_1.<locals>.Manager.__init__c                    s"   t d| j d| j gI d H  | S )Nzenter-1-zenter-2-r   r   r   r
   r
   r   
__aenter__  s    
z5CoroutineTest.test_with_1.<locals>.Manager.__aenter__c                    s0   t d| j d| j gI d H  | jdkr,dS d S )Nzexit-1-zexit-2-BTr   r	   r   r
   r
   r   	__aexit__  s
    

z4CoroutineTest.test_with_1.<locals>.Manager.__aexit__N)r   r   r   r   r   r   r
   r
   r
   r   Manager  s   r   c               
      s    d4 I d H t}  d4 I d H 8}t d| j|jfgI d H  dd  W d   I d H  qp1 I d H sf0    Y  W d   I d H  q1 I d H s0    Y  d S )NAr   managersr!   r   r   )r   r   r   r
   r   r=     s    $z&CoroutineTest.test_with_1.<locals>.foo)	z	enter-1-Az	enter-2-Az	enter-1-Bz	enter-2-B)r   r   r   zexit-1-Bzexit-2-Bzexit-1-Azexit-2-Ac               
      s    d4 I d H t}  d4 I d H 8}t d| j|jfgI d H  dd  W d   I d H  qp1 I d H sf0    Y  W d   I d H  q1 I d H s0    Y  d S )Nr   Cr   r!   r   r   )r   r   r   r
   r   r=     s    $)r   rA   r2   r   )r	   r=   rW   r   r}   r
   r   r   test_with_1  s    zCoroutineTest.test_with_1c                    sf   G dd d d  fdd}|  td t|  W d    n1 sL0    Y  | d d S )Nc                   @   s   e Zd Zdd ZdS )z%CoroutineTest.test_with_2.<locals>.CMc                 S   s   d S r   r
   r   r
   r
   r   r     s    z0CoroutineTest.test_with_2.<locals>.CM.__aenter__N)r   r   r   r   r
   r
   r
   r   CM  s   r   c                	      sF   d  4 I d H  dW d   I d H  qB1 I d H s80    Y  d S NFTr
   r
   r   Zbody_executedr
   r   r=     s    z&CoroutineTest.test_with_2.<locals>.foor   FrZ   AttributeErrorr   r   r\   r
   r   r   test_with_2  s    (zCoroutineTest.test_with_2c                    sf   G dd d d  fdd}|  td t|  W d    n1 sL0    Y  | d d S )Nc                   @   s   e Zd Zdd ZdS )z%CoroutineTest.test_with_3.<locals>.CMc                 S   s   d S r   r
   r   r
   r
   r   r     s    z/CoroutineTest.test_with_3.<locals>.CM.__aexit__N)r   r   r   r   r
   r
   r
   r   r     s   r   c                	      sF   d  4 I d H  dW d   I d H  qB1 I d H s80    Y  d S r   r
   r
   r   r
   r   r=     s    z&CoroutineTest.test_with_3.<locals>.foor   Fr   r\   r
   r   r   test_with_3  s    (zCoroutineTest.test_with_3c                    sf   G dd d d  fdd}|  td t|  W d    n1 sL0    Y  | d d S )Nc                   @   s   e Zd ZdS )z%CoroutineTest.test_with_4.<locals>.CMNr   r
   r
   r
   r   r     s   r   c                	      sF   d  4 I d H  dW d   I d H  qB1 I d H s80    Y  d S r   r
   r
   r   r
   r   r=     s    z&CoroutineTest.test_with_4.<locals>.foor   Fr   r\   r
   r   r   test_with_4  s    (zCoroutineTest.test_with_4c                    sR   G dd d  fdd}|  t t|  W d    n1 sD0    Y  d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z%CoroutineTest.test_with_5.<locals>.CMc                    s   | S r   r
   r   r
   r
   r   r     s    z0CoroutineTest.test_with_5.<locals>.CM.__aenter__c                    s   d S r   r
   )r	   excr
   r
   r   r     s    z/CoroutineTest.test_with_5.<locals>.CM.__aexit__Nr   r   r   r   r   r
   r
   r
   r   r     s   r   c                	      s>     4 I d H  W d   I d H  q:1 I d H s00    Y  d S r   r
   r
   r   r
   r   r     s    z'CoroutineTest.test_with_5.<locals>.func)r2   AssertionErrorr   )r	   r   r
   r  r   test_with_5  s    zCoroutineTest.test_with_5c                    sT   G dd d  fdd}|  td t|  W d    n1 sF0    Y  d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z%CoroutineTest.test_with_6.<locals>.CMc                 S   s   dS )N{   r
   r   r
   r
   r   r     s    z0CoroutineTest.test_with_6.<locals>.CM.__aenter__c                 W   s   dS Ni  r
   r	   er
   r
   r   r     s    z/CoroutineTest.test_with_6.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r     s   r   c                	      s>     4 I d H  W d   I d H  q:1 I d H s00    Y  d S r   r
   r
   r  r
   r   r=     s    z&CoroutineTest.test_with_6.<locals>.foozV'async with' received an object from __aenter__ that does not implement __await__: intr   r\   r
   r  r   test_with_6  s    zCoroutineTest.test_with_6c              
      s   G dd d  fdd}zt |  W nX ty } z@| |jd d | |jd u | t|jt W Y d }~nd }~0 0 | d d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z%CoroutineTest.test_with_7.<locals>.CMc                    s   | S r   r
   r   r
   r
   r   r     s    z0CoroutineTest.test_with_7.<locals>.CM.__aenter__c                 W   s   dS )Ni  r
   r  r
   r
   r   r     s    z/CoroutineTest.test_with_7.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r     s   r   c                	      sF     4 I d H  dd  W d   I d H  qB1 I d H s80    Y  d S Nr!   r   r
   r
   r  r
   r   r=     s    z&CoroutineTest.test_with_7.<locals>.foor   U'async with' received an object from __aexit__ that does not implement __await__: intz1invalid asynchronous context manager did not fail)	r   rd   r^   r   rB   r   
isinstancer   failr	   r=   r   r
   r  r   test_with_7  s    (zCoroutineTest.test_with_7c                    sX  dG dd d  fdd}|  td t|  W d    n1 sL0    Y  | d  fdd}|  td t|  W d    n1 s0    Y  | d	  fd
d}|  td t|  W d    n1 s0    Y  | d  fdd}|  td t|  W d    n1 s>0    Y  | d d S )Nr   c                   @   s   e Zd Zdd Zdd ZdS )z%CoroutineTest.test_with_8.<locals>.CMc                    s   | S r   r
   r   r
   r
   r   r   $  s    z0CoroutineTest.test_with_8.<locals>.CM.__aenter__c                 W   s   dS r  r
   r  r
   r
   r   r   '  s    z/CoroutineTest.test_with_8.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r   #  s   r   c                	      sF     4 I d H  d7 W d   I d H  qB1 I d H s80    Y  d S ro   r
   r
   r   CNTr
   r   r=   +  s    z&CoroutineTest.test_with_8.<locals>.foor  r!   c               
      sj   t dD ]\}   4 I d H 4 d7 W d   I d H   qfW d   I d H  q1 I d H sZ0    Y  qd S Nr    r!   r>   r;   r  r
   r   r=   7  s    r    c               
      sh   t dD ]Z}   4 I d H 2 d7 W d   I d H  qW d   I d H  q1 I d H sX0    Y  qd S r  r  r;   r  r
   r   r=   E  s    r   c                	      sH     4 I d H   d7 W d   I d H  d S 1 I d H s:0    Y  d S ro   r
   r
   r  r
   r   r=   S  s       )rZ   rd   r   rA   r\   r
   r  r   test_with_8   s<    (((*zCoroutineTest.test_with_8c                    sd   dG dd d  fdd}|  t t|  W d    n1 sJ0    Y  | d d S )Nr   c                   @   s   e Zd Zdd Zdd ZdS )z%CoroutineTest.test_with_9.<locals>.CMc                    s   | S r   r
   r   r
   r
   r   r   d  s    z0CoroutineTest.test_with_9.<locals>.CM.__aenter__c                    s   dd  d S r
  r
   r  r
   r
   r   r   g  s    z/CoroutineTest.test_with_9.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r   c  s   r   c                	      sF     4 I d H  d7 W d   I d H  qB1 I d H s80    Y  d S ro   r
   r
   r  r
   r   r=   j  s    z&CoroutineTest.test_with_9.<locals>.foor!   r2   r   r   rA   r\   r
   r  r   test_with_9`  s    (zCoroutineTest.test_with_9c              
      s   dG dd d  fdd}zt |  W nZ ty } zB| |jd u | t|jt | t|jjt W Y d }~nd }~0 0 | d d S )Nr   c                   @   s   e Zd Zdd Zdd ZdS )z&CoroutineTest.test_with_10.<locals>.CMc                    s   | S r   r
   r   r
   r
   r   r   x  s    z1CoroutineTest.test_with_10.<locals>.CM.__aenter__c                    s   dd  d S r
  r
   r  r
   r
   r   r   {  s    z0CoroutineTest.test_with_10.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r   w  s   r   c                
      s|     4 I d H T   4 I d H  t W d   I d H  qN1 I d H sD0    Y  W d   I d H  qx1 I d H sn0    Y  d S r   r[   r
   r  r
   r   r=   ~  s    z'CoroutineTest.test_with_10.<locals>.fooz*exception from __aexit__ did not propagate)r   r   rB   r   r  r[   r  r  r
   r  r   test_with_10t  s    zCoroutineTest.test_with_10c              
      sr   dG dd d  fdd}zt |  W n4 tyb } z| |jd u  W Y d }~nd }~0 0 | d d S )Nr   c                   @   s   e Zd Zdd Zdd ZdS )z&CoroutineTest.test_with_11.<locals>.CMc                    s   t d S r   )NotImplementedErrorr   r
   r
   r   r     s    z1CoroutineTest.test_with_11.<locals>.CM.__aenter__c                    s   dd  d S r
  r
   r  r
   r
   r   r     s    z0CoroutineTest.test_with_11.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r     s   r   c                	      sB     4 I d H  t W d   I d H  q>1 I d H s40    Y  d S r   r  r
   r  r
   r   r=     s    z'CoroutineTest.test_with_11.<locals>.fooz+exception from __aenter__ did not propagate)r   r  rB   r   r  r  r
   r  r   test_with_11  s    &zCoroutineTest.test_with_11c                    s0   dG dd d  fdd}t |  d S )Nr   c                   @   s   e Zd Zdd Zdd ZdS )z&CoroutineTest.test_with_12.<locals>.CMc                    s   | S r   r
   r   r
   r
   r   r     s    z1CoroutineTest.test_with_12.<locals>.CM.__aenter__c                    s   dS NTr
   r  r
   r
   r   r     s    z0CoroutineTest.test_with_12.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r     s   r   c               	      sP     4 I d H (}  | j  tW d   I d H  qL1 I d H sB0    Y  d S r   )r   	__class__r[   cmr   r  r	   r
   r   r=     s    z'CoroutineTest.test_with_12.<locals>.foo)r   r\   r
   r   r   test_with_12  s    zCoroutineTest.test_with_12c                    sd   dG dd d  fdd}|  t t|  W d    n1 sJ0    Y  | d d S )Nr   c                   @   s   e Zd Zdd Zdd ZdS )z&CoroutineTest.test_with_13.<locals>.CMc                    s   dd  d S r
  r
   r   r
   r
   r   r     s    z1CoroutineTest.test_with_13.<locals>.CM.__aenter__c                    s   dS r  r
   r  r
   r
   r   r     s    z0CoroutineTest.test_with_13.<locals>.CM.__aexit__Nr  r
   r
   r
   r   r     s   r   c                	      sV   d7   4 I d H  d7 W d   I d H  qJ1 I d H s@0    Y  d7 d S )Nr!   r   '  r
   r
   r  r
   r   r=     s    2z'CoroutineTest.test_with_13.<locals>.foor!   r  r\   r
   r  r   test_with_13  s    (zCoroutineTest.test_with_13c                    sH  dG fddd g  fdd}t | \}}| d | |dd tdd	D  | d
d tddD  g  fdd}t | \}}| d | |ddg | dd tddD dg  g  fdd}t | \}}| d | |dd tdd	D  | dd tddD ddg  d S )Nr   c                       s(   e Zd Zdd Z fddZdd ZdS )z+CoroutineTest.test_for_1.<locals>.AsyncIterc                 S   s
   d| _ d S r   r;   r   r
   r
   r   r     s    z4CoroutineTest.test_for_1.<locals>.AsyncIter.__init__c                    s    d7  | S ro   r
   r   aiter_callsr
   r   	__aiter__  s    z5CoroutineTest.test_for_1.<locals>.AsyncIter.__aiter__c                    sF   |  j d7  _ | j d s,t| j d I d H  | j dkr:t| j | j fS )Nr!   rN   r   )r$   r   StopAsyncIterationr   r
   r
   r   	__anext__  s    

z5CoroutineTest.test_for_1.<locals>.AsyncIter.__anext__Nr   r   r   r   r&  r(  r
   r$  r
   r   	AsyncIter  s   r*  c                     s,     2 z3 d H W \} } | |  q6 d S r   r   )Zi1Zi2r*  r   r
   r   test1  s    z'CoroutineTest.test_for_1.<locals>.test1r!   c                 S   s   g | ]}|d  qS r   r
   rf   r
   r
   r   rh     rI   z,CoroutineTest.test_for_1.<locals>.<listcomp>   c                 S   s   g | ]}|d  qS )r    r
   rf   r
   r
   r   rh     rI   e   c                     sL     2 z*3 d H W }  | d  | d dkr q>q6  d  d d S Nr      what?endr+  r;   r,  r
   r   test2  s    z'CoroutineTest.test_for_1.<locals>.test2r    r      c                 S   s   g | ]}|qS r
   r
   rf   r
   r
   r   rh     rI      r4  c                     sJ     2 z(3 d H W } | d dkr q | d  q6  d  d d S r1  r+  r;   r,  r
   r   test3  s    z'CoroutineTest.test_for_1.<locals>.test3r   c                 S   s   g | ]}|d  qS r.  r
   rf   r
   r
   r   rh     rI   c                 S   s   g | ]}|qS r
   r
   rf   r
   r
   r   rh     rI   r3  )r   rA   r>   )r	   r-  yieldedr}   r5  r8  r
   )r*  r%  r   r   
test_for_1  s,    
"
zCoroutineTest.test_for_1c                    sf   d t  } fdd}| td t|  W d    n1 sF0    Y  | t  | d S )Nr   c                     s     2 z3 d H W } t d q6 d S Nznever going to happenprintr;   tupr
   r   r=     s    z%CoroutineTest.test_for_2.<locals>.fooz/async for' requires an object.*__aiter__.*tuplesysgetrefcountrZ   rd   r   rA   )r	   refs_beforer=   r
   r>  r   
test_for_2  s    
(zCoroutineTest.test_for_2c                    sv   G dd d}|  t  } fdd}| td t|  W d    n1 sV0    Y  | t  | d S )Nc                   @   s   e Zd Zdd ZdS )z#CoroutineTest.test_for_3.<locals>.Ic                 S   s   | S r   r
   r   r
   r
   r   r&  $  s    z-CoroutineTest.test_for_3.<locals>.I.__aiter__Nr   r   r   r&  r
   r
   r
   r   I#  s   rF  c                     s     2 z3 d H W } t d q6 d S r;  r<  r;   Zaiterr
   r   r=   *  s    z%CoroutineTest.test_for_3.<locals>.fooz!that does not implement __anext__r@  r	   rF  rC  r=   r
   rG  r   
test_for_3"  s    
(zCoroutineTest.test_for_3c                    sv   G dd d}|  t  } fdd}| td t|  W d    n1 sV0    Y  | t  | d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z#CoroutineTest.test_for_4.<locals>.Ic                 S   s   | S r   r
   r   r
   r
   r   r&  8  s    z-CoroutineTest.test_for_4.<locals>.I.__aiter__c                 S   s   dS )Nr
   r
   r   r
   r
   r   r(  ;  s    z-CoroutineTest.test_for_4.<locals>.I.__anext__N)r   r   r   r&  r(  r
   r
   r
   r   rF  7  s   rF  c                     s     2 z3 d H W } t d q6 d S r;  r<  r;   rG  r
   r   r=   A  s    z%CoroutineTest.test_for_4.<locals>.fooz7async for' received an invalid object.*__anext__.*tupler@  rH  r
   rG  r   
test_for_46  s    
(zCoroutineTest.test_for_4c                    s  d G  fdddG dd d  t }t } fdd}t $ td t|  W d    n1 s0    Y  |  d	 | t | | t |  fd
d}t|  |  d  fdd}t|  |  d d S )Nr   c                       s$   e Zd Z fddZ fddZdS )z)CoroutineTest.test_for_6.<locals>.Managerc                    s    d7  d S )Nr"  r
   r   rF  r
   r   r   Q  s    z4CoroutineTest.test_for_6.<locals>.Manager.__aenter__c                    s    d7  d S )Ni r
   r   rK  r
   r   r   U  s    z3CoroutineTest.test_for_6.<locals>.Manager.__aexit__Nr  r
   rK  r
   r   r   P  s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )z*CoroutineTest.test_for_6.<locals>.Iterablec                 S   s
   d| _ d S r   r;   r   r
   r
   r   r   Z  s    z3CoroutineTest.test_for_6.<locals>.Iterable.__init__c                 S   s   | S r   r
   r   r
   r
   r   r&  ]  s    z4CoroutineTest.test_for_6.<locals>.Iterable.__aiter__c                    s"   | j dkrt|  j d7  _ | j S NrN   r!   )r$   r'  r   r
   r
   r   r(  `  s    
z4CoroutineTest.test_for_6.<locals>.Iterable.__anext__Nr)  r
   r
   r
   r   IterableY  s   rM  c               	      s`   4 I d H 2 2 z3 d H W }  d7  q6 W d   I d H  qT1 I d H sJ0    Y   d7  d S Nr!   r   r
   r;   )rF  iterablemanagerr
   r   mainm  s    6z&CoroutineTest.test_for_6.<locals>.mainerrori c               	      s    4 I d H 4  2 z3 d H W }  d7  q6 W d   I d H  qX1 I d H sN0    Y   d7   4 I d H 4  2 z3 d H W }  d7  qv6 W d   I d H  q1 I d H s0    Y   d7  d S rN  r
   r;   rF  rM  r   r
   r   rQ    s    66i c               	      s    4 I d H D  d7   2 z3 d H W }  d7  q6  d7  W d   I d H  qh1 I d H s^0    Y   d7   4 I d H D  d7   2 z3 d H W }  d7  q6  d7  W d   I d H  q1 I d H s0    Y   d7  d S )Nr   r!   i r   r
   r;   rS  r
   r   rQ    s    
4
4i9)rA  rB  r'   r(   r)   r   rA   )r	   Zmrefs_beforeZirefs_beforerQ  r
   )rF  rM  r   rO  rP  r   
test_for_6M  s(    	



(

zCoroutineTest.test_for_6c                    sd   dG dd d  fdd}|  t t|  W d    n1 sJ0    Y  | d d S )Nr   c                   @   s   e Zd Zdd ZdS )z$CoroutineTest.test_for_7.<locals>.AIc                 S   s   dd  d S r
  r
   r   r
   r
   r   r&    s    z.CoroutineTest.test_for_7.<locals>.AI.__aiter__NrE  r
   r
   r
   r   AI  s   rU  c                     s*     2 z3 d H W } d7 q6 d7 d S Nr!   rN   r
   r;   rU  r  r
   r   r=     s    z%CoroutineTest.test_for_7.<locals>.foor  r\   r
   rW  r   
test_for_7  s    (zCoroutineTest.test_for_7c              	      s   dG dd d  fdd}|  tL t $ td t|  W d    n1 s^0    Y  W d    n1 s|0    Y  | d d S )Nr   c                   @   s   e Zd Zdd ZdS )z$CoroutineTest.test_for_8.<locals>.AIc                 S   s   dd  d S r
  r
   r   r
   r
   r   r&    s    z.CoroutineTest.test_for_8.<locals>.AI.__aiter__NrE  r
   r
   r
   r   rU    s   rU  c                     s*     2 z3 d H W } d7 q6 d7 d S rV  r
   r;   rW  r
   r   r=     s    z%CoroutineTest.test_for_8.<locals>.foorR  )r2   r   r'   r(   r)   r   rA   r\   r
   rW  r   
test_for_8  s    

FzCoroutineTest.test_for_8c                    sj   G dd d  fdd}|  td}| d  W d    n1 sH0    Y  |j}| |jt d S )Nc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z$CoroutineTest.test_for_11.<locals>.Fc                 S   s   | S r   r
   r   r
   r
   r   r&    s    z.CoroutineTest.test_for_11.<locals>.F.__aiter__c                 S   s   | S r   r
   r   r
   r
   r   r(    s    z.CoroutineTest.test_for_11.<locals>.F.__anext__c                 S   s   dd  d S r
  r
   r   r
   r
   r   r     s    z.CoroutineTest.test_for_11.<locals>.F.__await__N)r   r   r   r&  r(  r   r
   r
   r
   r   F  s   rZ  c                     s     2 z3 d H W } q6 d S r   r
   )r}   rZ  r
   r   rQ    s    z'CoroutineTest.test_for_11.<locals>.mainz an invalid object from __anext__)rZ   rd   r   	exceptionrP   	__cause__r   )r	   rQ  r   errr
   r[  r   test_for_11  s    *zCoroutineTest.test_for_11c                    s|   G dd dt G dd dt g  fdd}|  | d  W d    n1 s`0    Y  | dg d S )Nc                   @   s   e Zd ZdS )z*CoroutineTest.test_for_tuple.<locals>.DoneNr   r
   r
   r
   r   Done  rI   r`  c                   @   s    e Zd ZdZdd Zdd ZdS )z+CoroutineTest.test_for_tuple.<locals>.AIterr   c                 S   s   | S r   r
   r   r
   r
   r   r&    s    z5CoroutineTest.test_for_tuple.<locals>.AIter.__aiter__c                    s.   | j t| krt|  j d7  _ | | j d  S ro   )r$   lenr'  r   r
   r
   r   r(    s    z5CoroutineTest.test_for_tuple.<locals>.AIter.__anext__Nr   r   r   r$   r&  r(  r
   r
   r
   r   AIter  s   rc  c                     s,    dg2 z3 d H W }  |  q
6 d S r   r+  r;   rc  r`  r   r
   r   r=     s    z)CoroutineTest.test_for_tuple.<locals>.foor   )r   rj   r2   r   rA   r\   r
   rd  r   test_for_tuple  s    
*zCoroutineTest.test_for_tuplec                    s|   G dd dt G dd dt g  fdd}|  | d  W d    n1 s`0    Y  | dg d S )Nc                   @   s   e Zd ZdS )z3CoroutineTest.test_for_stop_iteration.<locals>.DoneNr   r
   r
   r
   r   r`    rI   r`  c                   @   s    e Zd ZdZdd Zdd ZdS )z4CoroutineTest.test_for_stop_iteration.<locals>.AIterr   c                 S   s   | S r   r
   r   r
   r
   r   r&    s    z>CoroutineTest.test_for_stop_iteration.<locals>.AIter.__aiter__c                    s   | j r
t|  j d7  _ | jS ro   )r$   r'  r   r   r
   r
   r   r(    s    z>CoroutineTest.test_for_stop_iteration.<locals>.AIter.__anext__Nrb  r
   r
   r
   r   rc    s   rc  c                     s*    d2 z3 d H W }  |  q6 d S r   r+  r;   rd  r
   r   r=     s    z2CoroutineTest.test_for_stop_iteration.<locals>.foor   )r   r   r2   r   rA   r\   r
   rd  r   test_for_stop_iteration  s    
*z%CoroutineTest.test_for_stop_iterationc                    s   dd   fdd} fdd} fdd} fd	d
}|  t| g ddgf |  t| g ddhf |  t| g dddf |  t| g dddf d S )Nc                    s   | S r   r
   r;   r
   r
   r   rW     s    z$CoroutineTest.test_comp_1.<locals>.fc                      s    dd  d dfD I d H S )Nc                    s   g | ]}|I d H qS r   r
   rg   r   r
   r
   r   rh     rI   z?CoroutineTest.test_comp_1.<locals>.run_list.<locals>.<listcomp>r!   )   r
   r
   r   r
   r   run_list  s    z+CoroutineTest.test_comp_1.<locals>.run_listc                      s    dd  d dfD I d H S )Nc                    s   h | ]}|I d H qS r   r
   rg  r
   r
   r   	<setcomp>  rI   z=CoroutineTest.test_comp_1.<locals>.run_set.<locals>.<setcomp>r!   rh  r
   r
   r   r
   r   run_set  s    z*CoroutineTest.test_comp_1.<locals>.run_setc                      s    dd  d dfD I d H S )Nc                    s   i | ]}|I d H dqS )Nr   r
   rg  r
   r
   r   
<dictcomp>  rI   z@CoroutineTest.test_comp_1.<locals>.run_dict1.<locals>.<dictcomp>r!   rh  r
   r
   r   r
   r   	run_dict1  s    z,CoroutineTest.test_comp_1.<locals>.run_dict1c                      s$   dd t  d dgD I d H S )Nc                    s   i | ]\}}||I d H qS r   r
   )rg   r$   r   r
   r
   r   rl    rI   z@CoroutineTest.test_comp_1.<locals>.run_dict2.<locals>.<dictcomp>r!   rh  )	enumerater
   r   r
   r   	run_dict2  s    z,CoroutineTest.test_comp_1.<locals>.run_dict2r!   rh  r   )r!   rh  )r   r!   r   )r	   ri  rk  rm  ro  r
   r   r   test_comp_1  s    zCoroutineTest.test_comp_1c                    s~   dd   fdd}|  t| g g df  fdd}|  t| g h df  fd	d
}|  t| g ddhf d S )Nc                    s   | S r   r
   r;   r
   r
   r   rW   !  s    z$CoroutineTest.test_comp_2.<locals>.fc                      s0   dd  d d d ddgfD I d H S )Nc                    s    g | ]}|I d H D ]}|qqS r   r
   rg   r   sr
   r
   r   rh   %  s   z?CoroutineTest.test_comp_2.<locals>.run_list.<locals>.<listcomp> abcdefgr
   r
   r   r
   r   ri  $  s    z+CoroutineTest.test_comp_2.<locals>.run_list)r   r   r   ru  rv  c                      s,   dd   ddg dggfD I d H S )Nc                    s0   h | ](}|I d H D ]}|I d H D ]}|q qqS r   r
   )rg   r   rr  dr
   r
   r   rj  -  s   z=CoroutineTest.test_comp_2.<locals>.run_set.<locals>.<setcomp>rN      r2  r
   r
   r   r
   r   rk  ,  s
    z*CoroutineTest.test_comp_2.<locals>.run_set>   rN   r2  rx  c                      s&   dd   d dgfD I d H S )Nc                    s&   h | ]}|I d H D ]}|I d H qqS r   r
   rq  r
   r
   r   rj  8  s   z>CoroutineTest.test_comp_2.<locals>.run_set2.<locals>.<setcomp>rN   r2  r
   r
   r   r
   r   run_set27  s    z+CoroutineTest.test_comp_2.<locals>.run_set2rN   r2  r   )r	   ri  rk  ry  r
   r   r   test_comp_2   s     


zCoroutineTest.test_comp_2c                    s   dd   fdd}|  t| g ddgf  fdd}|  t| g ddhf  fd	d
}|  t| g dddf  fdd}|  t| g ddgf d S )Nc                 S  s   | D ]
}|V  qd S r   r
   r   r$   r
   r
   r   rW   A  s    z$CoroutineTest.test_comp_3.<locals>.fc                      s   dd  ddg2 I d H S )Nc                    s   g | z3 d H W }|d q6 S ro   r
   rf   r
   r
   r   rh   F  rI   z?CoroutineTest.test_comp_3.<locals>.run_list.<locals>.<listcomp>rN   r2  r
   r
   r   r
   r   ri  E  s    z+CoroutineTest.test_comp_3.<locals>.run_listr/  r7  c                      s   dd  ddg2 I d H S )Nc                    s   h | z3 d H W }|d q6 S ro   r
   rf   r
   r
   r   rj  L  rI   z=CoroutineTest.test_comp_3.<locals>.run_set.<locals>.<setcomp>rN   r2  r
   r
   r   r
   r   rk  K  s    z*CoroutineTest.test_comp_3.<locals>.run_setc                      s   dd  ddg2 I d H S )Nc                    s$   i | z3 d H W }|d |d q6 S rt   r
   rf   r
   r
   r   rl  R  rI   z?CoroutineTest.test_comp_3.<locals>.run_dict.<locals>.<dictcomp>rN   r2  r
   r
   r   r
   r   run_dictQ  s    z+CoroutineTest.test_comp_3.<locals>.run_dict      )r/  r7  c                     s*   dd  ddg2 } dd | 2 I d H S )Nc                 S  s    | z3 d H W }|d V  q6 d S ro   r
   rf   r
   r
   r   	<genexpr>X  rI   z=CoroutineTest.test_comp_3.<locals>.run_gen.<locals>.<genexpr>rN   r2  c                    s   g | z3 d H W }|d q6 S Nr   r
   rg   r   r
   r
   r   rh   Y  rI   z>CoroutineTest.test_comp_3.<locals>.run_gen.<locals>.<listcomp>r
   r   r   r
   r   run_genW  s    z*CoroutineTest.test_comp_3.<locals>.run_geno   y   r   r	   ri  rk  r|  r  r
   r   r   test_comp_3@  s*    


zCoroutineTest.test_comp_3c                    s   dd   fdd}|  t| g dgf  fdd}|  t| g dhf  fdd	}|  t| g dd
if  fdd}|  t| g dgf d S )Nc                 S  s   | D ]
}|V  qd S r   r
   r{  r
   r
   r   rW   _  s    z$CoroutineTest.test_comp_4.<locals>.fc                      s   dd  ddg2 I d H S )Nc                    s&   g | z3 d H W }|dkr|d q6 S rL  r
   rf   r
   r
   r   rh   d  rI   z?CoroutineTest.test_comp_4.<locals>.run_list.<locals>.<listcomp>rN   r2  r
   r
   r   r
   r   ri  c  s    z+CoroutineTest.test_comp_4.<locals>.run_listr7  c                      s   dd  ddg2 I d H S )Nc                    s&   h | z3 d H W }|dkr|d q6 S rL  r
   rf   r
   r
   r   rj  j  rI   z=CoroutineTest.test_comp_4.<locals>.run_set.<locals>.<setcomp>rN   r2  r
   r
   r   r
   r   rk  i  s    z*CoroutineTest.test_comp_4.<locals>.run_setc                      s   dd  ddg2 I d H S )Nc                    s,   i | z"3 d H W }|dkr|d |d q6 S )NrN   r!   r    r
   rf   r
   r
   r   rl  p  rI   z?CoroutineTest.test_comp_4.<locals>.run_dict.<locals>.<dictcomp>rN   r2  r
   r
   r   r
   r   r|  o  s    z+CoroutineTest.test_comp_4.<locals>.run_dictr~  c                     s*   dd  ddg2 } dd | 2 I d H S )Nc                 S  s(   | z3 d H W }|dkr|d V  q6 d S rL  r
   rf   r
   r
   r   r  v  rI   z=CoroutineTest.test_comp_4.<locals>.run_gen.<locals>.<genexpr>rN   r2  c                    s   g | z3 d H W }|d q6 S r  r
   r  r
   r
   r   rh   w  rI   z>CoroutineTest.test_comp_4.<locals>.run_gen.<locals>.<listcomp>r
   r   r   r
   r   r  u  s    z*CoroutineTest.test_comp_4.<locals>.run_genr  r   r  r
   r   r   test_comp_4^  s*    
zCoroutineTest.test_comp_4c                    s   dd   fdd}|  t| g g df  fdd}|  t| g h df  fd	d
}|  t| g ddddf  fdd}|  t| g g df d S )Nc                 S  s   | D ]
}|V  qd S r   r
   r{  r
   r
   r   rW   }  s    z&CoroutineTest.test_comp_4_2.<locals>.fc                      s   dd  t d2 I d H S )Nc                    s6   g | z,3 d H W }d|  k r$dk rn q|d q6 S Nr   r  rN   r
   rf   r
   r
   r   rh     rI   zACoroutineTest.test_comp_4_2.<locals>.run_list.<locals>.<listcomp>   r  r
   r   r
   r   ri    s    z-CoroutineTest.test_comp_4_2.<locals>.run_list)r/  r}     c                      s   dd  t d2 I d H S )Nc                    s6   h | z,3 d H W }d|  k r$dk rn q|d q6 S r  r
   rf   r
   r
   r   rj    rI   z?CoroutineTest.test_comp_4_2.<locals>.run_set.<locals>.<setcomp>r  r  r
   r   r
   r   rk    s    z,CoroutineTest.test_comp_4_2.<locals>.run_set>   r/  r}  r  c                      s   dd  t d2 I d H S )Nc                    s<   i | z23 d H W }d|  k r$dk rn q|d |d q6 S )Nr   r  rN   r   r
   rf   r
   r
   r   rl    rI   zACoroutineTest.test_comp_4_2.<locals>.run_dict.<locals>.<dictcomp>r  r  r
   r   r
   r   r|    s    z-CoroutineTest.test_comp_4_2.<locals>.run_dictr0  r   g   c                     s*   dd  t d2 } dd | 2 I d H S )Nc                 S  s8   | z.3 d H W }d|  k r"dk rn q|d V  q6 d S r  r
   rf   r
   r
   r   r    rI   z?CoroutineTest.test_comp_4_2.<locals>.run_gen.<locals>.<genexpr>r  c                    s   g | z3 d H W }|d q6 S r  r
   r  r
   r
   r   rh     rI   z@CoroutineTest.test_comp_4_2.<locals>.run_gen.<locals>.<listcomp>r  r   r   r
   r   r    s    z,CoroutineTest.test_comp_4_2.<locals>.run_gen)r  p   q   r   r  r
   r   r   test_comp_4_2|  s*    


zCoroutineTest.test_comp_4_2c                    s0   dd   fdd}|  t| g dgf d S )Nc                 S  s   | D ]
}|V  qd S r   r
   r{  r
   r
   r   rW     s    z$CoroutineTest.test_comp_5.<locals>.fc                      s$    fddddgddgfD I d H S )Nc              	      s@   g | ]8}|d  dkr |2 z3 dH W }|dkr|d q6 qS )r   rN   Nrx  r!   r
   )rg   Zpairr$   r   r
   r   rh     s   z?CoroutineTest.test_comp_5.<locals>.run_list.<locals>.<listcomp>rN   r2  rx  (   r
   r
   r   r
   r   ri    s    z+CoroutineTest.test_comp_5.<locals>.run_listrh  r   r	   ri  r
   r   r   test_comp_5  s    zCoroutineTest.test_comp_5c                    s2   dd   fdd}|  t| g g df d S )Nc                 S  s   | D ]
}|V  qd S r   r
   r{  r
   r
   r   rW     s    z$CoroutineTest.test_comp_6.<locals>.fc                      s   dd  ddg2 I d H S )Nc                    s(   g | z3 d H W }|D ]}|d qq6 S ro   r
   )rg   seqr$   r
   r
   r   rh     s   z?CoroutineTest.test_comp_6.<locals>.run_list.<locals>.<listcomp>)rN   r2  )rx  r
   r
   r   r
   r   ri    s    z+CoroutineTest.test_comp_6.<locals>.run_list)r/  r7     r   r  r
   r   r   test_comp_6  s    
zCoroutineTest.test_comp_6c                    sN   dd   fdd}|  td t|  W d    n1 s@0    Y  d S )Nc                   S  s   dV  dV  t dd S )Nr!   r    aaa)r   r
   r
   r
   r   rW     s    z$CoroutineTest.test_comp_7.<locals>.fc                      s   dd   2 I d H S )Nc                    s   g | z3 d H W }|q6 S r   r
   rf   r
   r
   r   rh     rI   z?CoroutineTest.test_comp_7.<locals>.run_list.<locals>.<listcomp>r
   r
   r   r
   r   ri    s    z+CoroutineTest.test_comp_7.<locals>.run_listr  )rZ   r   r   r  r
   r   r   test_comp_7  s    zCoroutineTest.test_comp_7c                 C   s&   dd }|  t| g g df d S )Nc                      s   dd dD S )Nc                 S   s   g | ]}|qS r
   r
   rf   r
   r
   r   rh     rI   z8CoroutineTest.test_comp_8.<locals>.f.<locals>.<listcomp>r   r
   r
   r
   r
   r   rW     s    z$CoroutineTest.test_comp_8.<locals>.fr   r   r	   rW   r
   r
   r   test_comp_8  s
    
zCoroutineTest.test_comp_8c                    s2   dd   fdd}|  t| g ddgf d S )Nc                   S  s   dV  dV  d S rt   r
   r
   r
   r
   r   rH     s    z&CoroutineTest.test_comp_9.<locals>.genc                     s$   dd   2 I d H } dd | D S )Nc                    s   g | z3 d H W }|q6 S r   r
   rf   r
   r
   r   rh     rI   z8CoroutineTest.test_comp_9.<locals>.f.<locals>.<listcomp>c                 S   s   g | ]}|qS r
   r
   rf   r
   r
   r   rh     rI   r
   )lr   r
   r   rW     s    z$CoroutineTest.test_comp_9.<locals>.fr!   r    r   r  r
   r   r   test_comp_9  s    
zCoroutineTest.test_comp_9c                 C   s*   dd }|  t| g ddddf d S )Nc                     s   dd dD } dd | D S )Nc                 S   s   h | ]}|qS r
   r
   rf   r
   r
   r   rj    rI   z8CoroutineTest.test_comp_10.<locals>.f.<locals>.<setcomp>r   c                 S   s   i | ]
}||qS r
   r
   )rg   xr
   r
   r   rl    rI   z9CoroutineTest.test_comp_10.<locals>.f.<locals>.<dictcomp>r
   )xxr
   r
   r   rW     s    z%CoroutineTest.test_comp_10.<locals>.fr!   r    r   r   r   r  r
   r
   r   test_comp_10  s
    zCoroutineTest.test_comp_10c                 C   s   dd }| }|  t t| W d    n1 s80    Y  | }z@|  t t| W d    n1 sv0    Y  W |  n
|  0 d S )Nc                      s   d S r   r
   r
   r
   r
   r   r     rI   z%CoroutineTest.test_copy.<locals>.func)r2   rd   copyr   r`   )r	   r   r   r#   r
   r
   r   	test_copy  s    (*zCoroutineTest.test_copyc              	   C   s   dd }| }t tjd D ]@}| ttjf t|| W d    q1 sR0    Y  q| }z\t tjd D ]@}| ttjf t|| W d    qv1 s0    Y  qvW |  n
|  0 d S )Nc                      s   d S r   r
   r
   r
   r
   r   r     rI   z'CoroutineTest.test_pickle.<locals>.funcr!   )	r>   pickleHIGHEST_PROTOCOLr2   rd   PicklingErrordumpsr   r`   )r	   r   r   protor#   r
   r
   r   test_pickle  s    ,.zCoroutineTest.test_picklec              	   C   s   dd }t   t \}t d | }t|}d }t  | dt|j	j
 | t|j	j| W d    n1 s|0    Y  W d    n1 s0    Y  d S )Nc                      s   d S r   r
   r
   r
   r
   r   r     rI   z3CoroutineTest.test_fatal_coro_warning.<locals>.funcrR  zwas never awaited)r'   r(   r   catch_unraisable_exceptionfilterwarningsr_   r*   r   str
unraisable	exc_valuerA   object)r	   r   r  r   	coro_reprr
   r
   r   test_fatal_coro_warning  s    

z%CoroutineTest.test_fatal_coro_warningc                    s   G dd d}| dd  fdd}  t| g df  fdd	}  t| g df  fd
d}  t| g df d S )Nc                   @   s   e Zd Zdd ZdS )zMCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.BadTargetc                 S   s   t dd S r   r'  )r	   keyr   r
   r
   r   __setitem__	  s    zYCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.BadTarget.__setitem__N)r   r   r   r  r
   r
   r
   r   	BadTarget  s   r  c                   S  s
   dV  d S rM   r
   r
   r
   r
   r   source  s    zJCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.sourcec                     sX     t*}  2 z3 d H W d< q6 W d    n1 s:0    Y   | jjd dS )Nr   r   r4  r2   r'  rA   r\  r   r  r	   r  tgtr
   r   run_for  s
    "zKCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_forr4  c                     sX     t*} fdd 2 I d H W  d    S 1 s:0    Y   | jjd dS )Nc                    s   g | z3 d H W  d< dq6 S r   r
   rg   r  r
   r   rh     rI   z`CoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_list.<locals>.<listcomp>r  r4  r  r  r  r
   r   ri    s    8zLCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_listc                     sx   fdd 2 } |  d } t}|I d H  W d    n1 sH0    Y   |jjt  |jjjd dS )Nc                   s    | z3 d H W  d< dV  q6 d S r   r
   r  r  r
   r   r    rI   z^CoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_gen.<locals>.<genexpr>r  r4  	asendr2   r[   rP   r\  r]  r'  rA   r   rH   r   r  r  r
   r   r    s    
(zKCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_genr   )r	   r  r  ri  r  r
   r  r   ,test_for_assign_raising_stop_async_iteration  s    z:CoroutineTest.test_for_assign_raising_stop_async_iterationc                    s   G dd d  fddfdd} t| g df fdd	} t| g df fd
d} t| g df d S )Nc                   @   s   e Zd Zdd ZdS )zQCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.BadIterablec                 S   s   t dd S r   r  r   r
   r
   r   r   *  s    zZCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.BadIterable.__iter__N)r   r   r   r   r
   r
   r
   r   BadIterable)  s   r  c                     s     V  d S r   r
   r
   )r  r
   r   badpairs,  s    zNCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.badpairsc                     sX    t*}   2 z3 d H W \}}q6 W d    n1 s:0    Y  | jjd dS )Nr  r4  r  )r  r$   jr  r	   r
   r   r  /  s
    "zMCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_forr4  c                     sT    t&} dd   2 I d H W  d    S 1 s60    Y  | jjd dS )Nc                    s   g | z3 d H W \}}dq6 S r   r
   rg   r$   r  r
   r
   r   rh   9  rI   zbCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_list.<locals>.<listcomp>r  r4  r  r  r  r
   r   ri  7  s    4zNCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_listc                     st   dd   2 } |  d }t}|I d H  W d    n1 sD0    Y  |jjt |jjjd dS )Nc                 S  s    | z3 d H W \}}dV  q6 d S r   r
   r  r
   r
   r   r  ?  rI   z`CoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_gen.<locals>.<genexpr>r  r4  r  r  r  r
   r   r  >  s    
(zMCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_genr   )r	   r  ri  r  r
   )r  r  r	   r   .test_for_assign_raising_stop_async_iteration_2(  s    z<CoroutineTest.test_for_assign_raising_stop_async_iteration_2N)Rr   r   r   rL   rX   r]   ra   rn   rs   ru   rx   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r!  r#  r:  rD  rI  rJ  rT  rX  rY  r_  re  rf  rp  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
   r
   r
   r   rG     s   	#
	(	
"(@H\ 	!rG   c                   @   s   e Zd Zdd ZdS )CoroAsyncIOCompatTestc              	      s   t dG dd dtg G fddd  fdd} }| z:z||  W n yz   Y n0 W |  d  n|  d  0 | g d d S )	Nasyncioc                   @   s   e Zd ZdS )z9CoroAsyncIOCompatTest.test_asyncio_1.<locals>.MyExceptionNr   r
   r
   r
   r   MyExceptionP  s   r  c                       s(   e Zd Z fddZ fddZdS )z0CoroAsyncIOCompatTest.test_asyncio_1.<locals>.CMc                    s(    d  dI d H   d | S )Nr!   {Gz?r    )r   sleepr   r  r   r
   r   r   V  s    

z;CoroAsyncIOCompatTest.test_asyncio_1.<locals>.CM.__aenter__c                    s      dI d H  |j d S )Nr  )r  r   r   )r	   exc_typeexc_valexc_tbr  r
   r   r   \  s    z:CoroAsyncIOCompatTest.test_asyncio_1.<locals>.CM.__aexit__Nr  r
   r  r
   r   r   U  s   r   c               	      s\     4 I d H *}  dI d H  W d   I d H  qN1 I d H sD0    Y  d d S )Nr  Zunreachable)r  r   r   r   r  r  r   r
   r   rW   `  s    .z/CoroAsyncIOCompatTest.test_asyncio_1.<locals>.f)r!   r    r  )	r   import_moduler   Znew_event_loopZset_event_loopZrun_until_completer`   Zset_event_loop_policyrA   )r	   rW   Zloopr
   r  r   test_asyncio_1K  s     

z$CoroAsyncIOCompatTest.test_asyncio_1N)r   r   r   r  r
   r
   r
   r   r  I  s   r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
OriginTrackingTestc                 C   s   t t  j}|j|jfS r   )rC   Zgetframeinfocurrentframef_backfilenamelineno)r	   infor
   r
   r   heret  s    zOriginTrackingTest.herec              	      s$  t  }zdd  t d t  d t  }|j W d    n1 s\0    Y  t d t  d  \}}t  *}|j||d dff W d    n1 s0    Y  t d t  d  fdd} \}}| \\}}}t|2 |j||d	f||d dff W d    n1 sX0    Y  t d
 t  6}	dt
|j  k od
k n   W d    n1 s0    Y  t t d W d    n1 s0    Y  t  d
 W t | nt | 0 d S )Nc                      s   d S r   r
   r
   r
   r
   r   corofn{  s    z7OriginTrackingTest.test_origin_tracking.<locals>.corofnr   r!   test_origin_trackingr    c                      s       fS r   )r  r
   r  r	   r
   r   nested  s    z7OriginTrackingTest.test_origin_tracking.<locals>.nestedr  r   )rA  #get_coroutine_origin_tracking_depth#set_coroutine_origin_tracking_depthrA   
contextlibclosingr   	cr_originr  rB   ra  r2   r   )r	   
orig_depthr   Zfnamer  r  Znested_fnameZnested_linenor
   r  r   r  x  s@    
*
"
$
F*z'OriginTrackingTest.test_origin_trackingc                    s  dd   \}}fdd |d7 }  \}} fdd|d7 }fdd	}t }z|d
dj d}|dddj ddd| d| ddg |dddj ddd| d| ddd| d| ddg W t| nt| 0 d S )Nc                      s   d S r   r
   r
   r
   r
   r   r    s    z?OriginTrackingTest.test_origin_tracking_warning.<locals>.corofnc                      s     S r   r
   r
   )r  r
   r   a1  s    z;OriginTrackingTest.test_origin_tracking_warning.<locals>.a1r    c                      s     S r   r
   r
   )r  r
   r   a2  s    z;OriginTrackingTest.test_origin_tracking_warning.<locals>.a2c                    sX   t |  t}   t  W d    n1 s80    Y  |t|j d S r   )	rA  r  ZassertWarnsr|   r   r*   rA   r  warning)depthmsgr  )r  r	   r
   r   rm     s
    
&z>OriginTrackingTest.test_origin_tracking_warning.<locals>.checkr   zcoroutine 'z' was never awaitedr!   rs  z' was never awaited
z-Coroutine created at (most recent call last)
z  File "z", line z, in a1
z$    return corofn()  # comment in a1z, in a2
z!    return a1()  # comment in a2
)r  rA  r  r   r@   r  )r	   Za1_filenameZ	a1_linenoZa2_filenameZ	a2_linenorm   r  r  r
   )r  r  r  r	   r   test_origin_tracking_warning  s4    

z/OriginTrackingTest.test_origin_tracking_warningc              	   C   s  dd }t j}zdd t _t z}tdtfL | }t|}~t  | t|j	j
| | |j	jt W d    n1 s0    Y  W d    n1 s0    Y  t `tdtf |  t  W d    n1 s0    Y  W |t _n|t _0 d S )Nc                      s   d S r   r
   r
   r
   r
   r   r    s    zLOriginTrackingTest.test_unawaited_warning_when_module_broken.<locals>.corofnc                 S   s   dd S r
  r
   rv   r
   r
   r   re     rI   zNOriginTrackingTest.test_unawaited_warning_when_module_broken.<locals>.<lambda>zcoroutine .* was never awaited)r'   _warn_unawaited_coroutiner   r  Zcheck_warningsr|   r_   r*   rA   r  r  r  r   )r	   r  Zorig_wucr  r   r  r
   r
   r   )test_unawaited_warning_when_module_broken  s,    

L(z<OriginTrackingTest.test_unawaited_warning_when_module_brokenN)r   r   r   r  r  r  r  r
   r
   r
   r   r  s  s   .*r  c                   @   s   e Zd Zdd ZdS )"UnawaitedWarningDuringShutdownTestc                 C   s.   d}t d| d}t d| d}t d| d S )Nz7import asyncio
async def f(): pass
asyncio.gather(f())
z-cz.import sys
async def f(): pass
sys.coro = f()
zYimport sys
async def f(): pass
sys.corocycle = [f()]
sys.corocycle.append(sys.corocycle)
r   )r	   r.   r
   r
   r   &test_unawaited_warning_during_shutdown  s    

zIUnawaitedWarningDuringShutdownTest.test_unawaited_warning_during_shutdownN)r   r   r   r  r
   r
   r
   r   r    s   r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )CAPITestc                    s0   ddl m   fdd}| | d d d S )Nr   	awaitTypec                     s    t dg} | I d H S ro   r   futureatr
   r   r=   	  s    z%CAPITest.test_tp_await_1.<locals>.foor!   )	_testcapir  rA   r   r\   r
   r  r   test_tp_await_1		  s    zCAPITest.test_tp_await_1c                 C   s2   ddl m} |tdg}| t| d d S )Nr   r  r!   )r  r  rl   rA   r"   r   )r	   r  r  r
   r
   r   test_tp_await_2	  s    zCAPITest.test_tp_await_2c                    s\   ddl m   fdd}| td$ | | d d W d    n1 sN0    Y  d S )Nr   r  c                     s    d} | I d H S ro   r
   r  r  r
   r   r=   	  s    z%CAPITest.test_tp_await_3.<locals>.fooz.__await__.*returned non-iterator of type 'int'r!   )r  r  rZ   rd   rA   r   r\   r
   r  r   test_tp_await_3	  s    zCAPITest.test_tp_await_3N)r   r   r   r  r  r  r
   r
   r
   r   r  	  s   	r  __main__)r  r  rC   r  rA  rQ   Zunittestr'   testr   Ztest.support.script_helperr   r   r   r   r%   contextmanagerr+   ZTestCaser,   r:   rG   r  r  r  Zcpython_onlyr  r   rQ  r
   r
   r
   r   <module>   sP   
               `*
