o
    g                     @   sF  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 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re  dS dS )    N)support)import_helper)warnings_helperassert_python_okc                   @      e Zd Zdd Zdd ZdS )AsyncYieldFromc                 C   
   || _ d S Nobj)selfr    r   J/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_coroutines.py__init__      
zAsyncYieldFrom.__init__c                 c   s    | j E d H  d S r
   r   r   r   r   r   	__await__      zAsyncYieldFrom.__await__N__name__
__module____qualname__r   r   r   r   r   r   r          r   c                   @   r   )
AsyncYieldc                 C   r	   r
   value)r   r   r   r   r   r      r   zAsyncYield.__init__c                 c   s    | j V  d S r
   r   r   r   r   r   r         zAsyncYield.__await__Nr   r   r   r   r   r      r   r   c              
   C   sv   | j tjtjhv sJ g }d }	 z
|| d  W n ty9 } z|jr*|jd nd }W Y d }~||fS d }~ww q)NTr   )	__class__typesGeneratorTypeCoroutineTypeappendsendStopIterationargs)corobufferresultexr   r   r   	run_async   s   
r*   c              
   C   s   | j tju sJ |  }g }d }d}	 z|d r |t| n||d  |d7 }W n tyL } z|jr=|jd nd }W Y d }~||fS d }~ww q)Nr   T      )	r   r   r!   r   r"   nextr#   r$   r%   )r&   awr'   r(   ir)   r   r   r   run_async__await__-   s$   
r0   c                   c   sH    t   t d d V  t  W d    d S 1 sw   Y  d S )Nignore)warningscatch_warningssimplefilterr   
gc_collectr   r   r   r   silence_coro_gc@   s   


"r6   c                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
AsyncBadSyntaxTestc              
   C   x   g d}|D ]3}| j |d# | t t|dd W d    n1 s%w   Y  W d    q1 s4w   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_1J   s     6 z#AsyncBadSyntaxTest.test_badsyntax_1c              
   C   r9   )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<   r=   r>   rB   r   r   r   test_badsyntax_2  s   " z#AsyncBadSyntaxTest.test_badsyntax_2c                 C   s<   |  t tddd W d    d S 1 sw   Y  d S )Nz	async = 1r<   r=   )r?   r@   rA   r   r   r   r   test_badsyntax_3  s   "z#AsyncBadSyntaxTest.test_badsyntax_3c              
   C   r9   )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<   r=   r>   rB   r   r   r   test_badsyntax_4  s   - z#AsyncBadSyntaxTest.test_badsyntax_4N)r   r   r   rC   rD   rE   rF   r   r   r   r   r8   H   s      ;'r8   c                   @      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joinr=   assertEqual
assertTrueinspectZiscoroutinefunction)r   bufr/   nsr   r   r   test_oneline_defs  s   
z#TokenizerRegrTest.test_oneline_defsN)r   r   r   rT   r   r   r   r   rH         rH   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       d V  d S r
   r   r   r   r   r   gen  s   
 z%CoroutineTest.test_gen_1.<locals>.genr   )assertFalsehasattr)r   rX   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                         dS N
   r   r   r   r   r   rK        z&CoroutineTest.test_func_1.<locals>.foor^   c                   S      d S r
   r   r   r   r   r   bar      z&CoroutineTest.test_func_1.<locals>.bar)assertIsInstancer   r!   rP   bool__code__co_flagsrQ   ZCO_COROUTINErY   ZCO_GENERATORcr_coderO   r*   r0   )r   rK   fra   r   r   r   test_func_1  s   zCoroutineTest.test_func_1c                 C   D   dd }|  td t|  W d    d S 1 sw   Y  d S )Nc                         t r
   r$   r   r   r   r   rK     r_   z&CoroutineTest.test_func_2.<locals>.foozcoroutine raised StopIteration)assertRaisesRegexRuntimeErrorr*   r   rK   r   r   r   test_func_2  s   "zCoroutineTest.test_func_2c                 C   s*   dd }| }|  t|d |  d S )Nc                      rk   r
   rl   r   r   r   r   rK     r_   z&CoroutineTest.test_func_3.<locals>.fooz^<coroutine object.* at 0x.*>$)assertRegexreprclose)r   rK   r&   r   r   r   test_func_3  s   zCoroutineTest.test_func_3c                    sB  dd }| } fdd}|  t | W d    n1 sw   Y  |  t| W d    n1 s6w   Y  |  t| W d    n1 sMw   Y  |  t| W d    n1 sdw   Y  |  |D ]}qoW d    n1 s|w   Y  |  dd |D  W d    n1 sw   Y  |  d S )Nc                      rk   r
   rl   r   r   r   r   rK      r_   z&CoroutineTest.test_func_4.<locals>.fooc                           tdS Nz"'coroutine' object is not iterablerm   	TypeErrorr   r   r   r   <lambda>$      z+CoroutineTest.test_func_4.<locals>.<lambda>c                 S      g | ]}|qS r   r   .0r/   r   r   r   
<listcomp>8      z-CoroutineTest.test_func_4.<locals>.<listcomp>)listtuplesumiterrs   )r   rK   r&   checkr/   r   r   r   test_func_4  s0   



zCoroutineTest.test_func_4c                    s   t jdd   fdd}fdd}| }|  |D ]}qW d    n1 s)w   Y  |    D ]}|d q5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   ra   =     
z&CoroutineTest.test_func_5.<locals>.barc                           I d H  d S r
   r   r   ra   r   r   rK   A  r   z&CoroutineTest.test_func_5.<locals>.fooc                      ru   rv   rw   r   r   r   r   ry   D  rz   z+CoroutineTest.test_func_5.<locals>.<lambda>r,   c                 S   r{   r   r   )r}   elr   r   r   r~   P  r   z-CoroutineTest.test_func_5.<locals>.<listcomp>r,   )r   	coroutiners   rO   r   r-   r   )r   rK   r   r&   r   r   )ra   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    d S 1 s8w   Y  d S )Nc                   s   s    dV  dV  d S Nr,   r+   r   r   r   r   r   ra   U  s   
z&CoroutineTest.test_func_6.<locals>.barc                      r   r
   r   r   r   r   r   rK   Z  r   z&CoroutineTest.test_func_6.<locals>.foor,   r+   )r   r   rO   r#   r?   r$   )r   rK   rh   r   r   r   test_func_6T  s   
"zCoroutineTest.test_func_6c                    s\   dd }|   fdd}|  td t|  W d    n1 s#w   Y     d S )Nc                      r\   r]   r   r   r   r   r   ra   d  r_   z&CoroutineTest.test_func_7.<locals>.barc                   3   s     E d H  d S r
   r   r   r&   r   r   rK   h     z&CoroutineTest.test_func_7.<locals>.foozCcannot 'yield from' a coroutine object in a non-coroutine generator)rm   rx   r   rs   r   ra   rK   r   r   r   test_func_7c  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   r   r   r   ra   t  r   z&CoroutineTest.test_func_8.<locals>.barc                      r\   Nspamr   r   r   r   r   rK   x  r_   z&CoroutineTest.test_func_8.<locals>.foor   )r   r   rO   r*   rs   r   r   r   r   test_func_8s  s   zCoroutineTest.test_func_8c              	   C   s   dd }|  td |  t  W d    n1 sw   Y  |  td( | t | D ]}q1W d    n1 s>w   Y  t  W d    d S 1 sRw   Y  d S )Nc                         d S r
   r   r   r   r   r   rK     r_   z&CoroutineTest.test_func_9.<locals>.fooz0coroutine '.*test_func_9.*foo' was never awaited)ZassertWarnsRegexRuntimeWarningr   r5   r?   rx   )r   rK   _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 s_w   Y  |  d	 d S )
Nr   c                  3   sJ    zz
d V } | d V  W n t y    d7   w W  d7  d S  d7  w )Nr+   d   r,   ZeroDivisionErrora)Nr   r   rX     s   z'CoroutineTest.test_func_10.<locals>.genc                      r   r
   r   r   rX   r   r   rK     r   z'CoroutineTest.test_func_10.<locals>.foor^   r   r,   f   )r   r   r   assertIsr   r-   rO   r#   rs   r?   r   throw)r   rK   r&   r.   r   )r   rX   r   test_func_10  s&   zCoroutineTest.test_func_10c                 C   sR   dd }| }|  dt| |  dt|  |  dt|  |  d S )Nc                      r   r
   r   r   r   r   r   func      z(CoroutineTest.test_func_11.<locals>.funcr   __iter__Zcoroutine_wrapper)assertIndirr   rr   rs   )r   r   r&   r   r   r   test_func_11  s   zCoroutineTest.test_func_11c                    sN    fdd}|  |  td  d  W d    d S 1 s w   Y  d S )Nc                     s     d } tI d H  d S r
   )r#   rK   rI   mer   r   g  s   
z%CoroutineTest.test_func_12.<locals>.gzcoroutine already executing)rm   
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w   Y  |  d S )Nc                      r   r
   r   r   r   r   r   r     r_   z%CoroutineTest.test_func_13.<locals>.gz5can't send non-None value to a just-started coroutiner   )rm   rx   r#   rs   )r   r   r&   r   r   r   test_func_13  s   zCoroutineTest.test_func_13c                    sd   t jdd   fdd}| }|d  | td |  W d    d S 1 s+w   Y  d S )Nc                   s   rW   r
   r   r   r   r   r   rX     r   z'CoroutineTest.test_func_14.<locals>.genc                      s6   z	  I d H  W d S  t y     I d H  Y d S w r
   GeneratorExitr   r   r   r   r&     s   z(CoroutineTest.test_func_14.<locals>.corozcoroutine ignored GeneratorExit)r   r   r#   rm   rn   rs   )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 s#w   Y  |  td ||d  W d    d S 1 sAw   Y  d S )Nc                      r\   r   r   r   r   r   r   spammer  r_   z+CoroutineTest.test_func_15.<locals>.spammerc                    s   | I d H S r
   r   r   r   r   r   reader     
z*CoroutineTest.test_func_15.<locals>.readerr   &cannot reuse already awaited coroutine)rm   r$   r#   rn   )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 s<w   Y  ||}|d  | td |d  W d    n1 s`w   Y  | td |td	 W d    d S 1 s~w   Y  d S )
Nc                   s   rW   r
   r   r   r   r   r   nop  r   z'CoroutineTest.test_func_16.<locals>.nopc                      s     I d H  dS r   r   r   r   r   r   r#     s   z(CoroutineTest.test_func_16.<locals>.sendc                    s     I d H  | I d H S r
   r   r   r   r   r   read   s   
z(CoroutineTest.test_func_16.<locals>.readhamr   wat)r   r   r#   rm   	Exceptionr   rn   )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w   Y  |  td |d  W d    n1 s8w   Y  |  td |td W d    n1 sUw   Y  |  |  d S )Nc                      r\   r   r   r   r   r   r   r     r_   z-CoroutineTest.test_func_17.<locals>.coroutiner   r   r   )rm   r$   r#   rn   r   r   rs   )r   r   r&   r   r   r   test_func_17  s"   zCoroutineTest.test_func_17c                 C   sF  dd }| }|  }t|}| td |d  W d    n1 s%w   Y  | td |d  W d    n1 s@w   Y  | td t| W d    n1 sZw   Y  | td |td W d    n1 sww   Y  | td |td W d    n1 sw   Y  |	  |	  d S )Nc                      r\   r   r   r   r   r   r   r   0  r_   z-CoroutineTest.test_func_18.<locals>.coroutiner   r   r   )
r   r   rm   r$   r#   rn   r-   r   r   rs   )r   r   r&   Z
await_iteritr   r   r   test_func_18-  s:   

zCoroutineTest.test_func_18c                    s   d t j fddfdd}| }|d  |d  |  d |  |  d tdD ]}|  |  d q2d S )Nr   c                   3   s2    d V  zd V  W d S  t y    d7  Y d S w r   r   r   )CHKr   r   rK   X  s   z'CoroutineTest.test_func_19.<locals>.fooc                      r   r
   r   r   )rK   r   r   r   a  r   z-CoroutineTest.test_func_19.<locals>.coroutiner,      )r   r   r#   rO   rs   rL   )r   r   r&   r   r   )r   rK   r   test_func_19U  s   

zCoroutineTest.test_func_19c                 C   s&   dd }t | }| |g df d S )Nc                      r\   )Nr^   r   r   r   r   r   rK   t  r_   z7CoroutineTest.test_coro_wrapper_send_tuple.<locals>.foor   )r0   rO   r   rK   r(   r   r   r   test_coro_wrapper_send_tuples  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 r]   rl   r   r   r   r   rK   {  s   z?CoroutineTest.test_coro_wrapper_send_stop_iterator.<locals>.foor,   r^   )r0   rc   r$   rO   r   r   r   r   r   $test_coro_wrapper_send_stop_iteratorz  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 sYw   Y  ttj j d S )Nc                   3   sL     t tj  j d V   t tj  j d S r
   )rO   rQ   getcoroutinestateZCORO_RUNNINGassertIsNonecr_awaitr   )coro_br   r   r   r     s   z&CoroutineTest.test_cr_await.<locals>.ac                      r   r
   r   r   r   r   r   r     r   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   )r   r   rO   rQ   r   ZCORO_CREATEDr   r   r#   ZCORO_SUSPENDEDgi_codeco_namer?   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   r   c                      r   r
   r   r   r   r   r   rh     r   z(CoroutineTest.test_corotype_1.<locals>.fzcoroutine object)r   r!   r   r#   __doc__rs   r   __dict__rO   r   rr   )r   ctrh   r   r   r   r   test_corotype_1  s   zCoroutineTest.test_corotype_1c                 C   rj   )Nc                      s   dI d H  d S r   r   r   r   r   r   rK     r   z'CoroutineTest.test_await_1.<locals>.foozobject int can.t.*awaitrm   rx   r*   ro   r   r   r   test_await_1  s   "zCoroutineTest.test_await_1c                 C   rj   )Nc                      s   g I d H  d S r
   r   r   r   r   r   rK     r   z'CoroutineTest.test_await_2.<locals>.foozobject list can.t.*awaitr   ro   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   rK        z'CoroutineTest.test_await_3.<locals>.foor   )rO   r*   r0   ro   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                      r\   N*   r   r   r   r   r   ra     r_   z'CoroutineTest.test_await_4.<locals>.barc                           I d H S r
   r   r   r   r   r   rK     r   z'CoroutineTest.test_await_4.<locals>.foor   rO   r*   ro   r   r   r   test_await_4  s   zCoroutineTest.test_await_4c                    V   G dd d  fdd}|  td t|  W d    d S 1 s$w   Y  d S )Nc                   @   rG   )z-CoroutineTest.test_await_5.<locals>.Awaitablec                 S   r`   r
   r   r   r   r   r   r        z7CoroutineTest.test_await_5.<locals>.Awaitable.__await__Nr   r   r   r   r   r   r   r   	Awaitable      r   c                      r   r
   r   r   r   r   r   rK     r   z'CoroutineTest.test_await_5.<locals>.foo(__await__.*returned non-iterator of typer   ro   r   r   r   test_await_5     "zCoroutineTest.test_await_5c                    s6   G dd d  fdd}|  t| dgd f d S )Nc                   @   rG   )z-CoroutineTest.test_await_6.<locals>.Awaitablec                 S   s
   t dgS )N4   r   r   r   r   r   r     r   z7CoroutineTest.test_await_6.<locals>.Awaitable.__await__Nr   r   r   r   r   r     r   r   c                      r   r
   r   r   r   r   r   rK     r   z'CoroutineTest.test_await_6.<locals>.foor   r   ro   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                   @   rG   )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     r   r   c                      r   r
   r   r   r   r   r   rK     r   z'CoroutineTest.test_await_7.<locals>.foor   r   r   ro   r   r   r   test_await_7  s   zCoroutineTest.test_await_7c                    r   )Nc                   @      e Zd ZdS )z-CoroutineTest.test_await_8.<locals>.AwaitableNr   r   r   r   r   r   r   r         r   c                      r   r
   r   r   r   r   r   rK     s    z'CoroutineTest.test_await_8.<locals>.fooz4object Awaitable can't be used in 'await' expressionr   ro   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 r
   r   r   r   r   r   wrap  r   z(CoroutineTest.test_await_9.<locals>.wrapc                      r\   r   r   r   r   r   r   ra     r_   z'CoroutineTest.test_await_9.<locals>.barc                     sr   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                      r   r
   r   r   r   r   r   ry      rb   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   ra   r   r   r   rK     s   ,z'CoroutineTest.test_await_9.<locals>.fooc                      s     I d H  S r
   r   r   r   r   r   foo2  r   z(CoroutineTest.test_await_9.<locals>.foo2i  ir   r   rK   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                      r\   r   r   r   r   r   r   baz  r_   z(CoroutineTest.test_await_10.<locals>.bazc                      s     S r
   r   r   )r   r   r   ra        z(CoroutineTest.test_await_10.<locals>.barc                      s     I d H I d H S r
   r   r   r   r   r   rK        z(CoroutineTest.test_await_10.<locals>.foor   r   ro   r   )ra   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 r
   r   valr   r   r   ident  r   z*CoroutineTest.test_await_11.<locals>.identc                      r\   r   r   r   r   r   r   ra     r_   z(CoroutineTest.test_await_11.<locals>.barc                      s     I d H dS )Nr  r   r   ra   r  r   r   rK   !  r   z(CoroutineTest.test_await_11.<locals>.fooc                      s     I d H dfS )Nr   r   r   r   r   r   r   $  r   z)CoroutineTest.test_await_11.<locals>.foo2)r   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 s,w   Y    d S )Nc                      r\   r   r   r   r   r   r   r&   *  r_   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                    r   r
   r   r   r   r   r   r   /  r   z8CoroutineTest.test_await_12.<locals>.Awaitable.__await__Nr   r   r  r   r   r   .  s    r   c                      r   r
   r   r   r   r   r   rK   2  r   z(CoroutineTest.test_await_12.<locals>.fooz"__await__\(\) returned a coroutine)rm   rx   r*   rs   )r   r&   rK   r   )r   r   r   test_await_12)  s   zCoroutineTest.test_await_12c                    r   )Nc                   @   rG   )z.CoroutineTest.test_await_13.<locals>.Awaitablec                 S   r  r
   r   r   r   r   r   r   =  r   z8CoroutineTest.test_await_13.<locals>.Awaitable.__await__Nr   r   r   r   r   r   <  r   r   c                      r   r
   r   r   r   r   r   rK   @  r   z(CoroutineTest.test_await_13.<locals>.foor   r   ro   r   r   r   test_await_13;  r   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 sBw   Y  | }|d  |  |t W d    d S 1 sew   Y  d S )Nc                   @   r   )z,CoroutineTest.test_await_14.<locals>.Wrapperc                 S   s   |j tju sJ || _d S r
   )r   r   r!   r&   )r   r&   r   r   r   r   K  s   
z5CoroutineTest.test_await_14.<locals>.Wrapper.__init__c                 S   s
   | j  S r
   )r&   r   r   r   r   r   r   N  r   z6CoroutineTest.test_await_14.<locals>.Wrapper.__await__Nr   r   r   r   r   WrapperI  s    r
  c                   @   rG   )z/CoroutineTest.test_await_14.<locals>.FutureLikec                 s   s    d V S r
   r   r   r   r   r   r   R  r   z9CoroutineTest.test_await_14.<locals>.FutureLike.__await__Nr   r   r   r   r   
FutureLikeQ  r   r  c                   @   r   )z+CoroutineTest.test_await_14.<locals>.MarkerNr   r   r   r   r   MarkerU  r   r  c                      s$   z  I d H W S  t y   w r
   r   r   )r  r  r   r   coro1X  s   z*CoroutineTest.test_await_14.<locals>.coro1c                      s     I d H S r
   r   r   )r
  r  r   r   coro2]  r   z*CoroutineTest.test_await_14.<locals>.coro2r   )r   r#   rm   r$   r?   r   r   )r   r  r   r   )r  r  r
  r  r   test_await_14H  s   

"zCoroutineTest.test_await_14c                    sr   t jdd   fdd}dd }| }|d  | td ||d  W d    d S 1 s2w   Y  d S )Nc                   s   rW   r
   r   r   r   r   r   r   k  r   z(CoroutineTest.test_await_15.<locals>.nopc                      r   r
   r   r   r   r   r   r   o  r   z.CoroutineTest.test_await_15.<locals>.coroutinec                    s   | I d H  d S r
   r   r   r   r   r   waiterr  r   z+CoroutineTest.test_await_15.<locals>.waiterz"coroutine is being awaited already)r   r   r#   rm   rn   )r   r   r  r&   r   r   r   test_await_15j  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   rh     r   z&CoroutineTest.test_await_16.<locals>.fc                      s   zt      I d H  Y S r
   )KeyErrorr   rh   r   r   r     s
   z&CoroutineTest.test_await_16.<locals>.g)r*   r   __context__)r   r   r   r(   r   r  r   test_await_16|  s   zCoroutineTest.test_await_16c                    s   G dd d  fdd}| }t |\}}| |g d  fdd}| t t |  W d    d S 1 s:w   Y  d S )Nc                   @   $   e Zd Zdd Zdd Zdd ZdS )z*CoroutineTest.test_with_1.<locals>.Managerc                 S   r	   r
   )name)r   r  r   r   r   r     r   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                    s2   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               
          d4 I d H ;}  d4 I d H }t d| j|jfgI d H  dd  W d   I d H  q91 I d H s4w   Y  W d   I d H  d S 1 I d H sJw   Y  d S )NAr  managersr,   r   r  )r   r   r  r   r   rK     
   $
Xz&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               
      r  )Nr  Cr   r,   r   r  )r   r   r!  r   r   rK     r"  )r*   rO   r?   r   )r   rK   rh   r(   r   r   r!  r   test_with_1  s   "zCoroutineTest.test_with_1c                    f   G dd d d  fdd}|  td t|  W d    n1 s&w   Y  | d d S )Nc                   @   rG   )z%CoroutineTest.test_with_2.<locals>.CMc                 S   r`   r
   r   r   r   r   r   r    r   z0CoroutineTest.test_with_2.<locals>.CM.__aenter__N)r   r   r   r  r   r   r   r   CM  r   r&  c                	      J   d  4 I d H  dW d   I d H  d S 1 I d H sw   Y  d S NFTr   r   r&  Zbody_executedr   r   rK     
   .z&CoroutineTest.test_with_2.<locals>.foor  Frm   AttributeErrorr*   r   ro   r   r)  r   test_with_2     zCoroutineTest.test_with_2c                    r%  )Nc                   @   rG   )z%CoroutineTest.test_with_3.<locals>.CMc                 S   r`   r
   r   r   r   r   r   r    r   z/CoroutineTest.test_with_3.<locals>.CM.__aexit__N)r   r   r   r  r   r   r   r   r&    r   r&  c                	      r'  r(  r   r   r)  r   r   rK     r*  z&CoroutineTest.test_with_3.<locals>.foor  Fr+  ro   r   r)  r   test_with_3  r.  zCoroutineTest.test_with_3c                    r%  )Nc                   @   r   )z%CoroutineTest.test_with_4.<locals>.CMNr   r   r   r   r   r&    r   r&  c                	      r'  r(  r   r   r)  r   r   rK     r*  z&CoroutineTest.test_with_4.<locals>.foor  Fr+  ro   r   r)  r   test_with_4  s   zCoroutineTest.test_with_4c                    sT   G dd d  fdd}|  t t|  W d    d S 1 s#w   Y  d S )Nc                   @   r   )z%CoroutineTest.test_with_5.<locals>.CMc                       | S r
   r   r   r   r   r   r    r_   z0CoroutineTest.test_with_5.<locals>.CM.__aenter__c                    r   r
   r   )r   excr   r   r   r    r_   z/CoroutineTest.test_with_5.<locals>.CM.__aexit__Nr   r   r   r  r  r   r   r   r   r&    r   r&  c                	      sN     4 I d H  ddksJ W d   I d H  d S 1 I d H s w   Y  d S )Nr   r,   r   r   r&  r   r   r     s   .z'CoroutineTest.test_with_5.<locals>.func)r?   AssertionErrorr*   )r   r   r   r4  r   test_with_5  s
   "zCoroutineTest.test_with_5c                    r   )Nc                   @   r   )z%CoroutineTest.test_with_6.<locals>.CMc                 S      dS )N{   r   r   r   r   r   r    r   z0CoroutineTest.test_with_6.<locals>.CM.__aenter__c                 W   r7  Ni  r   r   er   r   r   r    r   z/CoroutineTest.test_with_6.<locals>.CM.__aexit__Nr3  r   r   r   r   r&    r   r&  c                	      sB     4 I d H  W d   I d H  d S 1 I d H sw   Y  d S r
   r   r   r4  r   r   rK     s   .z&CoroutineTest.test_with_6.<locals>.foozV'async with' received an object from __aenter__ that does not implement __await__: intr   ro   r   r4  r   test_with_6  s   "zCoroutineTest.test_with_6c              
      s   G dd d  fdd}zt |  W n- tyA } z!| |jd d | |jd u | t|jt W Y d }~d S d }~ww | d d S )Nc                   @   r   )z%CoroutineTest.test_with_7.<locals>.CMc                    r1  r
   r   r   r   r   r   r  
  r_   z0CoroutineTest.test_with_7.<locals>.CM.__aenter__c                 W   r7  )Ni  r   r:  r   r   r   r    r   z/CoroutineTest.test_with_7.<locals>.CM.__aexit__Nr3  r   r   r   r   r&  	  r   r&  c                	      sJ     4 I d H  dd  W d   I d H  d S 1 I d H sw   Y  d S Nr,   r   r   r   r4  r   r   rK     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*   rx   rq   r%   rP   r  
isinstancer   failr   rK   r2  r   r4  r   test_with_7  s    zCoroutineTest.test_with_7c                    sV  dG dd d  fdd}|  td t|  W d    n1 s&w   Y  | d  fdd}|  td t|  W d    n1 sNw   Y  | d	  fd
d}|  td t|  W d    n1 svw   Y  | d  fdd}|  td t|  W d    n1 sw   Y  | d d S )Nr   c                   @   r   )z%CoroutineTest.test_with_8.<locals>.CMc                    r1  r
   r   r   r   r   r   r  &  r_   z0CoroutineTest.test_with_8.<locals>.CM.__aenter__c                 W   r7  r9  r   r:  r   r   r   r  )  r   z/CoroutineTest.test_with_8.<locals>.CM.__aexit__Nr3  r   r   r   r   r&  %  r   r&  c                	      J     4 I d H  d7 W d   I d H  d S 1 I d H sw   Y  d S r   r   r   r&  CNTr   r   rK   -     
.z&CoroutineTest.test_with_8.<locals>.foor>  r,   c               
      s\   t dD ]&}   4 I d H  d7 	 W d   I d H   d S 1 I d H s&w   Y  qd S Nr+   r,   rL   rI   rD  r   r   rK   9  s   0r+   c               
      sX   t dD ]$}   4 I d H  d7 	 W d   I d H  q1 I d H s$w   Y  qd S rG  rH  rI   rD  r   r   rK   G  s   ,r   c                	      sL     4 I d H  d7 	 W d   I d H  d S 1 I d H sw   Y  d S r   r   r   rD  r   r   rK   U  s
   0   )rm   rx   r*   rO   ro   r   rD  r   test_with_8"  sD   zCoroutineTest.test_with_8c                    d   dG dd d  fdd}|  t t|  W d    n1 s%w   Y  | d d S )Nr   c                   @   r   )z%CoroutineTest.test_with_9.<locals>.CMc                    r1  r
   r   r   r   r   r   r  f  r_   z0CoroutineTest.test_with_9.<locals>.CM.__aenter__c                       dd  d S r=  r   r:  r   r   r   r  i  r   z/CoroutineTest.test_with_9.<locals>.CM.__aexit__Nr3  r   r   r   r   r&  e  r   r&  c                	      rC  r   r   r   rD  r   r   rK   l  rF  z&CoroutineTest.test_with_9.<locals>.foor,   r?   r   r*   rO   ro   r   rD  r   test_with_9b  s   zCoroutineTest.test_with_9c              
      s   dG dd d  fdd}zt |  W n. tyE } z"| |jd u | t|jt | t|jjt W Y d }~d S d }~ww | d d S )Nr   c                   @   r   )z&CoroutineTest.test_with_10.<locals>.CMc                    r1  r
   r   r   r   r   r   r  z  r_   z1CoroutineTest.test_with_10.<locals>.CM.__aenter__c                    rL  r=  r   r:  r   r   r   r  }  r   z0CoroutineTest.test_with_10.<locals>.CM.__aexit__Nr3  r   r   r   r   r&  y  r   r&  c                
      sl     4 I d H !   4 I d H  t 1 I d H sw   Y  W d   I d H  d S 1 I d H s/w   Y  d S r
   rn   r   rD  r   r   rK     s   .z'CoroutineTest.test_with_10.<locals>.fooz*exception from __aexit__ did not propagate)r*   r   rP   r  r?  rn   r@  rA  r   rD  r   test_with_10v  s   zCoroutineTest.test_with_10c              
      st   dG dd d  fdd}zt |  W n ty2 } z| |jd u  W Y d }~d S d }~ww | d d S )Nr   c                   @   r   )z&CoroutineTest.test_with_11.<locals>.CMc                    rk   r
   )NotImplementedErrorr   r   r   r   r    r_   z1CoroutineTest.test_with_11.<locals>.CM.__aenter__c                    rL  r=  r   r:  r   r   r   r    r   z0CoroutineTest.test_with_11.<locals>.CM.__aexit__Nr3  r   r   r   r   r&    r   r&  c                	      s0     4 I d H  t 1 I d H sw   Y  d S r
   rO  r   rD  r   r   rK     s   z'CoroutineTest.test_with_11.<locals>.fooz+exception from __aenter__ did not propagate)r*   rQ  rP   r  r@  rA  r   rD  r   test_with_11  s   zCoroutineTest.test_with_11c                    s0   dG dd d  fdd}t |  d S )Nr   c                   @   r   )z&CoroutineTest.test_with_12.<locals>.CMc                    r1  r
   r   r   r   r   r   r    r_   z1CoroutineTest.test_with_12.<locals>.CM.__aenter__c                    r\   NTr   r:  r   r   r   r    r_   z0CoroutineTest.test_with_12.<locals>.CM.__aexit__Nr3  r   r   r   r   r&    r   r&  c               	      s>     4 I d H 
}  | j  t1 I d H sw   Y  d S r
   )r   r   rn   cmr&  rE  r   r   r   rK     s
   z'CoroutineTest.test_with_12.<locals>.foo)r*   ro   r   rV  r   test_with_12  s   zCoroutineTest.test_with_12c                    rK  )Nr   c                   @   r   )z&CoroutineTest.test_with_13.<locals>.CMc                    rL  r=  r   r   r   r   r   r    r   z1CoroutineTest.test_with_13.<locals>.CM.__aenter__c                    r\   rS  r   r:  r   r   r   r    r_   z0CoroutineTest.test_with_13.<locals>.CM.__aexit__Nr3  r   r   r   r   r&    r   r&  c                	      sX   d7   4 I d H  d7 W d   I d H  q&1 I d H s!w   Y  d7 d S )Nr,   r   '  r   r   rD  r   r   rK     s   
(z'CoroutineTest.test_with_13.<locals>.foor,   rM  ro   r   rD  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   
   d| _ d S Nr   rI   r   r   r   r   r     r   z4CoroutineTest.test_for_1.<locals>.AsyncIter.__init__c                    s    d7  | S r   r   r   aiter_callsr   r   	__aiter__  s   z5CoroutineTest.test_for_1.<locals>.AsyncIter.__aiter__c                    sH   |  j d7  _ | j d st| j d I d H  | j dkrt| j | j fS )Nr,   r^   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    rb  c                     s.     2 z3 d H W \} } | |  q6 d S r
   r"   )Zi1Zi2rb  r'   r   r   test1  s   z'CoroutineTest.test_for_1.<locals>.test1r,   c                 S      g | ]}|d  qS r   r   r|   r   r   r   r~         z,CoroutineTest.test_for_1.<locals>.<listcomp>   c                 S   rf  )r+   r   r|   r   r   r   r~     rh  e   c                     sN     2 z3 d H W }  | d  | d dkr q q6  d  d d S Nr      what?endrc  rI   rd  r   r   test2  s   
z'CoroutineTest.test_for_1.<locals>.test2r+   r      c                 S   r{   r   r   r|   r   r   r   r~      r      rn  c                     sL     2 z3 d H W } | d dkrq | d  q6  d  d d S rk  rc  rI   rd  r   r   test3  s   
z'CoroutineTest.test_for_1.<locals>.test3r   c                 S   rf  rg  r   r|   r   r   r   r~     rh  c                 S   r{   r   r   r|   r   r   r   r~     r   rm  )r*   rO   rL   )r   re  yieldedr   ro  rr  r   )rb  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 s#w   Y  | t  | d S )Nr   c                     "    2 z
3 d H W } t d q6 d S Nznever going to happenprintrI   tupr   r   rK        
z%CoroutineTest.test_for_2.<locals>.fooz/async for' requires an object.*__aiter__.*tuplesysgetrefcountrm   rx   r*   rO   )r   refs_beforerK   r   ry  r   
test_for_2  s   
zCoroutineTest.test_for_2c                    v   G dd d}|  t  } fdd}| td t|  W d    n1 s+w   Y  | t  | d S )Nc                   @   rG   )z#CoroutineTest.test_for_3.<locals>.Ic                 S   r  r
   r   r   r   r   r   r^  &  r   z-CoroutineTest.test_for_3.<locals>.I.__aiter__Nr   r   r   r^  r   r   r   r   I%  r   r  c                     ru  rv  rw  rI   aiterr   r   rK   ,  r{  z%CoroutineTest.test_for_3.<locals>.fooz!that does not implement __anext__r|  r   r  r  rK   r   r  r   
test_for_3$  s   
zCoroutineTest.test_for_3c                    r  )Nc                   @   r   )z#CoroutineTest.test_for_4.<locals>.Ic                 S   r  r
   r   r   r   r   r   r^  :  r   z-CoroutineTest.test_for_4.<locals>.I.__aiter__c                 S   r7  )Nr   r   r   r   r   r   r`  =  r   z-CoroutineTest.test_for_4.<locals>.I.__anext__N)r   r   r   r^  r`  r   r   r   r   r  9  r   r  c                     ru  rv  rw  rI   r  r   r   rK   C  r{  z%CoroutineTest.test_for_4.<locals>.fooz7async for' received an invalid object.*__anext__.*tupler|  r  r   r  r   
test_for_48  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 sCw   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                        d7  d S )NrX  r   r   r  r   r   r  S     z4CoroutineTest.test_for_6.<locals>.Manager.__aenter__c                    r  )Ni r   r  r  r   r   r  W  r  z3CoroutineTest.test_for_6.<locals>.Manager.__aexit__Nr3  r   r  r   r   r  R  s    r  c                   @   r  )z*CoroutineTest.test_for_6.<locals>.Iterablec                 S   rZ  r[  rI   r   r   r   r   r   \  r   z3CoroutineTest.test_for_6.<locals>.Iterable.__init__c                 S   r  r
   r   r   r   r   r   r^  _  r   z4CoroutineTest.test_for_6.<locals>.Iterable.__aiter__c                    s$   | j dkrt|  j d7  _ | j S Nr^   r,   )r/   r_  r   r   r   r   r`  b  s
   
z4CoroutineTest.test_for_6.<locals>.Iterable.__anext__Nra  r   r   r   r   Iterable[  s    r  c               	      sb   4 I d H  2 z
3 d H W }  d7  q
6 W d   I d H  q+1 I d H s&w   Y   d7  d S Nr,   r   r   rI   )r  iterablemanagerr   r   maino  s   
(z&CoroutineTest.test_for_6.<locals>.mainerrori c               	      s    4 I d H   2 z
3 d H W }  d7  q6 W d   I d H  q-1 I d H s(w   Y   d7   4 I d H   2 z
3 d H W }  d7  q<6 W d   I d H  q]1 I d H sXw   Y   d7  d S r  r   rI   r  r  r  r   r   r    s   
(
(i c               	      s    4 I d H "  d7   2 z
3 d H W }  d7  q6  d7  W d   I d H  q51 I d H s0w   Y   d7   4 I d H "  d7   2 z
3 d H W }  d7  qH6  d7  W d   I d H  qm1 I d H shw   Y   d7  d S )Nr   r,   i r   r   rI   r  r   r   r    s"   

(

(i9)r}  r~  r2   r3   r4   r*   rO   )r   Zmrefs_beforeZirefs_beforer  r   )r  r  r  r  r  r   
test_for_6O  s*   	





zCoroutineTest.test_for_6c                    sd   dG dd d  fdd}|  t t|  W d    n1 s%w   Y  | d d S )Nr   c                   @   rG   )z$CoroutineTest.test_for_7.<locals>.AIc                 S      dd  d S r=  r   r   r   r   r   r^       z.CoroutineTest.test_for_7.<locals>.AI.__aiter__Nr  r   r   r   r   AI  r   r  c                     ,     2 z
3 d H W } d7 q6 d7 d S Nr,   r^   r   rI   r  rE  r   r   rK     
   
z%CoroutineTest.test_for_7.<locals>.foorM  ro   r   r  r   
test_for_7  s   zCoroutineTest.test_for_7c              	      s   dG dd d  fdd}|  t& t  td t|  W d    n1 s/w   Y  W d    n1 s>w   Y  | d d S )Nr   c                   @   rG   )z$CoroutineTest.test_for_8.<locals>.AIc                 S   r  r=  r   r   r   r   r   r^    r  z.CoroutineTest.test_for_8.<locals>.AI.__aiter__Nr  r   r   r   r   r    r   r  c                     r  r  r   rI   r  r   r   rK     r  z%CoroutineTest.test_for_8.<locals>.foor  )r?   r   r2   r3   r4   r*   rO   ro   r   r  r   
test_for_8  s   

zCoroutineTest.test_for_8c                    sj   G dd d  fdd}|  td}| d  W d    n1 s$w   Y  |j}| |jt d S )Nc                   @   r  )z$CoroutineTest.test_for_11.<locals>.Fc                 S   r  r
   r   r   r   r   r   r^    r   z.CoroutineTest.test_for_11.<locals>.F.__aiter__c                 S   r  r
   r   r   r   r   r   r`    r   z.CoroutineTest.test_for_11.<locals>.F.__anext__c                 S   r  r=  r   r   r   r   r   r     r  z.CoroutineTest.test_for_11.<locals>.F.__await__N)r   r   r   r^  r`  r   r   r   r   r   F  s    r  c                     s     2 z3 d H W } q6 d S r
   r   )r   r  r   r   r    s   z'CoroutineTest.test_for_11.<locals>.mainz an invalid object from __anext__)rm   rx   r#   	exceptionrc   	__cause__r   )r   r  r   errr   r  r   test_for_11  s   zCoroutineTest.test_for_11c                    |   G dd dt G dd dt g  fdd}|  | d  W d    n1 s0w   Y  | dg d S )Nc                   @   r   )z*CoroutineTest.test_for_tuple.<locals>.DoneNr   r   r   r   r   Done      r  c                   @       e Zd ZdZdd Zdd ZdS )z+CoroutineTest.test_for_tuple.<locals>.AIterr   c                 S   r  r
   r   r   r   r   r   r^    r   z5CoroutineTest.test_for_tuple.<locals>.AIter.__aiter__c                    s0   | j t| kr
t|  j d7  _ | | j d  S r   )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      r  c                     s*    dg2 z3 d H W }  |  q6 r   rc  rI   r  r  r(   r   r   rK     s
   z)CoroutineTest.test_for_tuple.<locals>.foor   )r   r   r?   r#   rO   ro   r   r  r   test_for_tuple     
zCoroutineTest.test_for_tuplec                    r  )Nc                   @   r   )z3CoroutineTest.test_for_stop_iteration.<locals>.DoneNr   r   r   r   r   r    r  r  c                   @   r  )z4CoroutineTest.test_for_stop_iteration.<locals>.AIterr   c                 S   r  r
   r   r   r   r   r   r^    r   z>CoroutineTest.test_for_stop_iteration.<locals>.AIter.__aiter__c                    s    | j rt|  j d7  _ | jS r   )r/   r_  r   r   r   r   r   r`    s
   z>CoroutineTest.test_for_stop_iteration.<locals>.AIter.__anext__Nr  r   r   r   r   r    r  r  c                     s(    d2 z3 d H W }  |  q6 r   rc  rI   r  r   r   rK     s
   z2CoroutineTest.test_for_stop_iteration.<locals>.foor   )r   r$   r?   r#   rO   ro   r   r  r   test_for_stop_iteration  r  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                    r1  r
   r   rI   r   r   r   rh     r_   z$CoroutineTest.test_comp_1.<locals>.fc                      "   dd  d dfD I d H S )Nc                    s   g | ]}|I d H qS r
   r   r}   r   r   r   r   r~         z?CoroutineTest.test_comp_1.<locals>.run_list.<locals>.<listcomp>r,   )   r   r   r  r   r   run_list      z+CoroutineTest.test_comp_1.<locals>.run_listc                      r  )Nc                    s   h | ]}|I d H qS r
   r   r  r   r   r   	<setcomp>  r  z=CoroutineTest.test_comp_1.<locals>.run_set.<locals>.<setcomp>r,   r  r   r   r  r   r   run_set  r  z*CoroutineTest.test_comp_1.<locals>.run_setc                      r  )Nc                    s   i | ]}|I d H dqS )Nr   r   r  r   r   r   
<dictcomp>  s    z@CoroutineTest.test_comp_1.<locals>.run_dict1.<locals>.<dictcomp>r,   r  r   r   r  r   r   	run_dict1  r  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   )r}   r/   r   r   r   r   r    s    z@CoroutineTest.test_comp_1.<locals>.run_dict2.<locals>.<dictcomp>r,   r  )	enumerater   r  r   r   	run_dict2     $z,CoroutineTest.test_comp_1.<locals>.run_dict2r,   r  r   )r,   r  )r   r,   r   )r   r  r  r  r  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                    r1  r
   r   rI   r   r   r   rh   #  r_   z$CoroutineTest.test_comp_2.<locals>.fc                      s2   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   r}   r   sr   r   r   r~   '  s    
z?CoroutineTest.test_comp_2.<locals>.run_list.<locals>.<listcomp> abcdefgr   r   r  r   r   r  &  s   0z+CoroutineTest.test_comp_2.<locals>.run_list)r   r   r   r  r  c                      s.   dd   ddg dggfD I d H S )Nc                    s2   h | ]}|I d H D ]}|I d H D ]}|qq
qS r
   r   )r}   r   r  dr   r   r   r  /  s    z=CoroutineTest.test_comp_2.<locals>.run_set.<locals>.<setcomp>r^      rl  r   r   r  r   r   r  .  s   z*CoroutineTest.test_comp_2.<locals>.run_set>   r^   rl  r  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   r  r   r   r   r  :  s    z>CoroutineTest.test_comp_2.<locals>.run_set2.<locals>.<setcomp>r^   rl  r   r   r  r   r   run_set29  s   z+CoroutineTest.test_comp_2.<locals>.run_set2r^   rl  r   )r   r  r  r  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     | D ]}|V  qd S r
   r   r   r/   r   r   r   rh   C     z$CoroutineTest.test_comp_3.<locals>.fc                         dd  ddg2 I d H S )Nc                        g | z
3 d H W }|d q6 S r   r   r|   r   r   r   r~   H      z?CoroutineTest.test_comp_3.<locals>.run_list.<locals>.<listcomp>r^   rl  r   r   r  r   r   r  G     z+CoroutineTest.test_comp_3.<locals>.run_listri  rq  c                      r  )Nc                    s    h | z
3 d H W }|d q6 S r   r   r|   r   r   r   r  N  r  z=CoroutineTest.test_comp_3.<locals>.run_set.<locals>.<setcomp>r^   rl  r   r   r  r   r   r  M  r  z*CoroutineTest.test_comp_3.<locals>.run_setc                      r  )Nc                    s&   i | z3 d H W }|d |d q6 S r   r   r|   r   r   r   r  T  s   $ z?CoroutineTest.test_comp_3.<locals>.run_dict.<locals>.<dictcomp>r^   rl  r   r   r  r   r   run_dictS  r  z+CoroutineTest.test_comp_3.<locals>.run_dict      )ri  rq  c                     ,   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 r   r   r|   r   r   r   	<genexpr>Z       z=CoroutineTest.test_comp_3.<locals>.run_gen.<locals>.<genexpr>r^   rl  c                    r  Nr   r   r}   r   r   r   r   r~   [  r  z>CoroutineTest.test_comp_3.<locals>.run_gen.<locals>.<listcomp>r   r   r  r   r   run_genY     z*CoroutineTest.test_comp_3.<locals>.run_geno   y   r   r   r  r  r  r  r   r  r   test_comp_3B  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  r  r
   r   r  r   r   r   rh   a  r  z$CoroutineTest.test_comp_4.<locals>.fc                      r  )Nc                    s(   g | z3 d H W }|dkr|d q6 S r  r   r|   r   r   r   r~   f     & z?CoroutineTest.test_comp_4.<locals>.run_list.<locals>.<listcomp>r^   rl  r   r   r  r   r   r  e  r  z+CoroutineTest.test_comp_4.<locals>.run_listrq  c                      r  )Nc                    s(   h | z3 d H W }|dkr|d q6 S r  r   r|   r   r   r   r  l  r  z=CoroutineTest.test_comp_4.<locals>.run_set.<locals>.<setcomp>r^   rl  r   r   r  r   r   r  k  r  z*CoroutineTest.test_comp_4.<locals>.run_setc                      r  )Nc                    s.   i | z3 d H W }|dkr|d |d q6 S )Nr^   r,   r+   r   r|   r   r   r   r  r  s   , z?CoroutineTest.test_comp_4.<locals>.run_dict.<locals>.<dictcomp>r^   rl  r   r   r  r   r   r  q  r  z+CoroutineTest.test_comp_4.<locals>.run_dictr  c                     r  )Nc                 S  s*   | z3 d H W }|dkr|d V  q6 d S r  r   r|   r   r   r   r  x  s   ( z=CoroutineTest.test_comp_4.<locals>.run_gen.<locals>.<genexpr>r^   rl  c                    r  r  r   r  r   r   r   r~   y  r  z>CoroutineTest.test_comp_4.<locals>.run_gen.<locals>.<listcomp>r   r   r  r   r   r  w  r  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  r  r
   r   r  r   r   r   rh     r  z&CoroutineTest.test_comp_4_2.<locals>.fc                         dd  t d2 I d H S )Nc                    s8   g | z3 d H W }d|  k rdk rn q|d q6 S Nr   rI  r^   r   r|   r   r   r   r~        6 zACoroutineTest.test_comp_4_2.<locals>.run_list.<locals>.<listcomp>   rH  r   r  r   r   r    r  z-CoroutineTest.test_comp_4_2.<locals>.run_list)ri  r     c                      r  )Nc                    s8   h | z3 d H W }d|  k rdk rn q|d q6 S r  r   r|   r   r   r   r    r  z?CoroutineTest.test_comp_4_2.<locals>.run_set.<locals>.<setcomp>r  rH  r   r  r   r   r    r  z,CoroutineTest.test_comp_4_2.<locals>.run_set>   ri  r  r  c                      r  )Nc                    s>   i | z3 d H W }d|  k rdk rn q|d |d q6 S )Nr   rI  r^   r   r   r|   r   r   r   r    s   < zACoroutineTest.test_comp_4_2.<locals>.run_dict.<locals>.<dictcomp>r  rH  r   r  r   r   r    r  z-CoroutineTest.test_comp_4_2.<locals>.run_dictrj  r   g   c                     s,   dd  t d2 } dd | 2 I d H S )Nc                 S  s:   | z3 d H W }d|  k rdk rn q|d V  q6 d S r  r   r|   r   r   r   r    s   8 z?CoroutineTest.test_comp_4_2.<locals>.run_gen.<locals>.<genexpr>r  c                    r  r  r   r  r   r   r   r~     r  z@CoroutineTest.test_comp_4_2.<locals>.run_gen.<locals>.<listcomp>rH  r   r  r   r   r    r  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  r  r
   r   r  r   r   r   rh     r  z$CoroutineTest.test_comp_5.<locals>.fc                      s&    fddddgddgfD I d H S )Nc              	      sB   g | ]}|d  dkr |2 z3 dH W }|dkr|d q6 qS )r   r^   Nr  r,   r   )r}   Zpairr/   r  r   r   r~     s    z?CoroutineTest.test_comp_5.<locals>.run_list.<locals>.<listcomp>r^   rl  r  (   r   r   r  r   r   r    r  z+CoroutineTest.test_comp_5.<locals>.run_listr  r   r   r  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  r  r
   r   r  r   r   r   rh     r  z$CoroutineTest.test_comp_6.<locals>.fc                      r  )Nc                    s*   g | z3 d H W }|D ]}|d qq6 S r   r   )r}   seqr/   r   r   r   r~     s    z?CoroutineTest.test_comp_6.<locals>.run_list.<locals>.<listcomp>)r^   rl  )r  r   r   r  r   r   r    r  z+CoroutineTest.test_comp_6.<locals>.run_list)ri  rq     r   r  r   r  r   test_comp_6  s   
zCoroutineTest.test_comp_6c                    sP   dd   fdd}|  td t|  W d    d S 1 s!w   Y  d S )Nc                   S  s   dV  dV  t d)Nr,   r+   aaa)r   r   r   r   r   rh     s   z$CoroutineTest.test_comp_7.<locals>.fc                      s   dd   2 I d H S )Nc                       g | z3 d H W }|q6 S r
   r   r|   r   r   r   r~         z?CoroutineTest.test_comp_7.<locals>.run_list.<locals>.<listcomp>r   r   r  r   r   r    r   z+CoroutineTest.test_comp_7.<locals>.run_listr  )rm   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   r{   r   r   r|   r   r   r   r~     r   z8CoroutineTest.test_comp_8.<locals>.f.<locals>.<listcomp>r   r   r   r   r   r   rh     r   z$CoroutineTest.test_comp_8.<locals>.fr   r   r   rh   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 r   r   r   r   r   r   rX     s   
z&CoroutineTest.test_comp_9.<locals>.genc                     s&   dd   2 I d H } dd | D S )Nc                    r  r
   r   r|   r   r   r   r~     r  z8CoroutineTest.test_comp_9.<locals>.f.<locals>.<listcomp>c                 S   r{   r   r   r|   r   r   r   r~     r   r   )lr   r   r   rh     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   r|   r   r   r   r    r   z8CoroutineTest.test_comp_10.<locals>.f.<locals>.<setcomp>r   c                 S   s   i | ]}||qS r   r   )r}   xr   r   r   r    s    z9CoroutineTest.test_comp_10.<locals>.f.<locals>.<dictcomp>r   )xxr   r   r   rh     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 sw   Y  | }z(|  t t| W d    n1 s;w   Y  W |  d S W |  d S |  w )Nc                      r   r
   r   r   r   r   r   r     r   z%CoroutineTest.test_copy.<locals>.func)r?   rx   copyr   rs   )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 s)w   Y  q| }z/t tjd D ] }| ttjf t|| W d    q;1 sVw   Y  q;W |  d S |  w )Nc                      r   r
   r   r   r   r   r   r     r   z'CoroutineTest.test_pickle.<locals>.funcr,   )	rL   pickleHIGHEST_PROTOCOLr?   rx   PicklingErrordumpsr   rs   )r   r   r&   protor.   r   r   r   test_pickle  s   zCoroutineTest.test_picklec              	   C   s   dd }t  K t .}t d | }t|}d }t  | dt|j	j
 | t|j	j| W d    n1 s>w   Y  W d    d S W d    d S 1 sVw   Y  d S )Nc                      r   r
   r   r   r   r   r   r     r   z3CoroutineTest.test_fatal_coro_warning.<locals>.funcr  zwas never awaited)r2   r3   r   catch_unraisable_exceptionfilterwarningsrr   r5   r   str
unraisable	exc_valuerO   object)r   r   rU  r&   	coro_reprr   r   r   test_fatal_coro_warning  s   

Pz%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                   @   rG   )zMCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.BadTargetc                 S      t dr   r_  )r   keyr   r   r   r   __setitem__     zYCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.BadTarget.__setitem__N)r   r   r   r  r   r   r   r   	BadTarget
  r   r  c                   S  s   dV  d S r]   r   r   r   r   r   source  r   zJCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.sourcec                     sZ     t}  2 z3 d H W d< q
6 W d    n1 sw   Y   | jjd dS )Nr   r   rn  r?   r_  rO   r  r%   rT  r   r  tgtr   r   run_for     zKCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_forrn  c                     sZ     t} fdd 2 I d H W  d    S 1 sw   Y   | jjd dS )Nc                    s    g | z
3 d H W  d< dq6 S r[  r   r}   r  r   r   r~     r  z`CoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_list.<locals>.<listcomp>r  rn  r  rT  r  r   r   r    s    zLCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_listc                     sz   fdd 2 } |  d } t}|I d H  W d    n1 s%w   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  !  r  z^CoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_gen.<locals>.<genexpr>r  rn  	asendr?   rn   rc   r  r  r_  rO   r%   rX   r   rU  r  r   r   r     s   
zKCoroutineTest.test_for_assign_raising_stop_async_iteration.<locals>.run_genr   )r   r  r  r  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                   @   rG   )zQCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.BadIterablec                 S   r	  r   r
  r   r   r   r   r   ,  r  zZCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.BadIterable.__iter__N)r   r   r   r   r   r   r   r   BadIterable+  r   r  c                     s     V  d S r
   r   r   )r  r   r   badpairs.  r   zNCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.badpairsc                     sZ    t}   2 z3 d H W \}}q
6 W d    n1 sw   Y  | jjd dS )Nr  rn  r  )rU  r/   jr  r   r   r   r  1  r  zMCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_forrn  c                     sV    t} dd   2 I d H W  d    S 1 sw   Y  | jjd dS )Nc                    s    g | z
3 d H W \}}dq6 S r[  r   r}   r/   r  r   r   r   r~   ;  r  zbCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_list.<locals>.<listcomp>r  rn  r  rT  r  r   r   r  9  s    zNCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_listc                     sv   dd   2 } |  d }t}|I d H  W d    n1 s#w   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  A  r  z`CoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_gen.<locals>.<genexpr>r  rn  r  r  r  r   r   r  @  s   
zMCoroutineTest.test_for_assign_raising_stop_async_iteration_2.<locals>.run_genr   )r   r  r  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   r[   ri   rp   rt   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/  r0  r6  r<  rB  rJ  rN  rP  rR  rW  rY  rt  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   rV     s    	#
	(	
"(@H\ 	!rV   c                   @   rG   )CoroAsyncIOCompatTestc              	      s   t dG dd dtg G fddd  fdd} }| zz||  W n	 y=   Y nw W |  d  n
|  d  w | g d d S )	Nasyncioc                   @   r   )z9CoroAsyncIOCompatTest.test_asyncio_1.<locals>.MyExceptionNr   r   r   r   r   MyExceptionR  r   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  X  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__Nr3  r   r'  r   r   r&  W  s    r&  c               	      sJ     4 I d H }  dI d H  1 I d H sw   Y  d d S )Nr%  Zunreachable)r&  r"   r  r&  r$  r#  r'   r   r   rh   b  s   z/CoroAsyncIOCompatTest.test_asyncio_1.<locals>.f)r,   r+   r$  )	r   import_moduler   Znew_event_loopZset_event_loopZrun_until_completers   Zset_event_loop_policyrO   )r   rh   Zloopr   r+  r   test_asyncio_1M  s$   

z$CoroAsyncIOCompatTest.test_asyncio_1N)r   r   r   r-  r   r   r   r   r"  K  rU   r"  c                   @   r7   )
OriginTrackingTestc                 C   s   t t  j}|j|jfS r
   )rQ   Zgetframeinfocurrentframef_backfilenamelineno)r   infor   r   r   herev  s   zOriginTrackingTest.herec              	      s  t  }zdd  t d t  d t  }|j W d    n1 s.w   Y  t d t  d  \}}t  }|j||d dff W d    n1 sdw   Y  t d t  d  fdd} \}}| \\}}}t| |j||d	f||d dff W d    n1 sw   Y  t d
 t  }	dt
|j  k od
k n   W d    n1 sw   Y  t t d W d    n1 sw   Y  t  d
 W t | d S t | w )Nc                      r   r
   r   r   r   r   r   corofn}  r_   z7OriginTrackingTest.test_origin_tracking.<locals>.corofnr   r,   test_origin_trackingr+   c                      s       fS r
   )r4  r   r5  r   r   r   nested  s   z7OriginTrackingTest.test_origin_tracking.<locals>.nestedr8  r   )r}  #get_coroutine_origin_tracking_depth#set_coroutine_origin_tracking_depthrO   
contextlibclosingr   	cr_originr4  rP   r  r?   r   )r   
orig_depthr&   fnamer2  r8  Znested_fnameZnested_linenor   r7  r   r6  z  sJ   



&z'OriginTrackingTest.test_origin_trackingc                    s  dd   \}}fdd |d7 }  \}} fdd|d7 }fdd	}t }zK|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| d S t| w )Nc                      r   r
   r   r   r   r   r   r5    r_   z?OriginTrackingTest.test_origin_tracking_warning.<locals>.corofnc                           S r
   r   r   )r5  r   r   a1     z;OriginTrackingTest.test_origin_tracking_warning.<locals>.a1r+   c                      rA  r
   r   r   )rB  r   r   a2  rC  z;OriginTrackingTest.test_origin_tracking_warning.<locals>.a2c                    sX   t |  t}   t  W d    n1 sw   Y  |t|j d S r
   )	r}  r;  ZassertWarnsr   r   r5   rO   r  warning)ZdepthmsgrU  )rD  r   r   r   r     s   

z>OriginTrackingTest.test_origin_tracking_warning.<locals>.checkr   zcoroutine 'z' was never awaitedr,   r  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
)r4  r}  r:  r   rN   r;  )r   Za1_filenameZ	a1_linenoZa2_filenameZ	a2_linenor   r?  rF  r   )rB  rD  r5  r   r   test_origin_tracking_warning  s4   

z/OriginTrackingTest.test_origin_tracking_warningc              	   C   s  dd }t j}zzdd t _t =}tdtf& | }t|}~t  | 	t|j
j| | 	|j
jt W d    n1 sBw   Y  W d    n1 sQw   Y  t `tdtf |  t  W d    n1 sqw   Y  W |t _d S W |t _d S |t _w )Nc                      r   r
   r   r   r   r   r   r5    r_   zLOriginTrackingTest.test_unawaited_warning_when_module_broken.<locals>.corofnc                 S   s   dd S r=  r   r   r   r   r   ry     s    zNOriginTrackingTest.test_unawaited_warning_when_module_broken.<locals>.<lambda>zcoroutine .* was never awaited)r2   _warn_unawaited_coroutiner   r  r   Zcheck_warningsr   rr   r5   rO   r  r  r(  r   )r   r5  Zorig_wucrU  r&   r  r   r   r   )test_unawaited_warning_when_module_broken  s<   

 

z<OriginTrackingTest.test_unawaited_warning_when_module_brokenN)r   r   r   r4  r6  rG  rI  r   r   r   r   r.  u  s
    .*r.  c                   @   rG   )"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   rK  r   r   r   r   rJ    rU   rJ  c                   @   r  )CAPITestc                    s0   ddl m   fdd}| | d d d S )Nr   	awaitTypec                     s    t dg} | I d H S r   r   futureatr   r   rK   	  s   
z%CAPITest.test_tp_await_1.<locals>.foor,   )	_testcapirN  rO   r#   ro   r   rQ  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   rM  r,   )rS  rN  r   rO   r-   r   )r   rR  rP  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    d S 1 s(w   Y  d S )Nr   rM  c                     s    d} | I d H S r   r   rO  rQ  r   r   rK   	  s   
z%CAPITest.test_tp_await_3.<locals>.fooz.__await__.*returned non-iterator of type 'int'r,   )rS  rN  rm   rx   rO   r#   ro   r   rQ  r   test_tp_await_3	  s   "zCAPITest.test_tp_await_3N)r   r   r   rT  rU  rV  r   r   r   r   rL  		  s    	rL  __main__) r<  r  rQ   r  r}  r   Zunittestr2   testr   Ztest.supportr   r   Ztest.support.script_helperr   r   r   r*   r0   contextmanagerr6   ZTestCaser8   rH   rV   r"  r.  rJ  Zcpython_onlyrL  r   r  r   r   r   r   <module>   sZ    
               `* 