B
    u9ar  ã               @   sª   d dl Z d dlZd dlZd dlmZ edƒZG dd„ deƒZejddœdd	„ƒZ	d
d„ Z
dd„ ZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZedkr¦e ¡  dS )é    N)Úimport_moduleÚasyncioc               @   s   e Zd ZdS )ÚAwaitExceptionN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú#/usr/lib/python3.7/test_asyncgen.pyr   	   s   r   F)Úthrowc             c   s   | rdV  ndV  d S )N)r
   )Úresultr   )r
   r   r   r	   Ú	awaitable   s    r   c          
   C   sf   d}x\y"|rd}|   t¡}n
|  d ¡}W n( tk
rP } z
|jd S d }~X Y nX |dkrd}qW d S )NFr   )r
   T)r
   r   ÚsendÚStopIterationÚargs)ÚcoroÚexcÚfutÚexr   r   r	   Úrun_until_complete   s    r   c                s   ‡ fdd„}t |ƒ ƒS )Nc           	   “   s>   g } x4ˆ 2 y3 d H }W n
 t k
s.X |  |¡ q
   Y  W | S )N)ÚStopAsyncIterationÚappend)ÚresÚi)Úgenr   r	   Úiterate&   s    zto_list.<locals>.iterate)r   )r   r   r   )r   r	   Úto_list%   s    r   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚAsyncGenSyntaxTestc          	   C   s,   d}|   td¡ t|i i ƒ W d Q R X d S )NzJasync def foo():
            await abc
            yield from 123
        zyield from.*inside async)ÚassertRaisesRegexÚSyntaxErrorÚexec)ÚselfÚcoder   r   r	   Útest_async_gen_syntax_011   s    z+AsyncGenSyntaxTest.test_async_gen_syntax_01c          	   C   s,   d}|   td¡ t|i i ƒ W d Q R X d S )Nz4async def foo():
            yield from 123
        zyield from.*inside async)r   r   r   )r    r!   r   r   r	   Útest_async_gen_syntax_02:   s    z+AsyncGenSyntaxTest.test_async_gen_syntax_02c          	   C   s,   d}|   td¡ t|i i ƒ W d Q R X d S )NzXasync def foo():
            await abc
            yield
            return 123
        zreturn.*value.*async gen)r   r   r   )r    r!   r   r   r	   Útest_async_gen_syntax_03B   s    z+AsyncGenSyntaxTest.test_async_gen_syntax_03c          	   C   s,   d}|   td¡ t|i i ƒ W d Q R X d S )NzBasync def foo():
            yield
            return 123
        zreturn.*value.*async gen)r   r   r   )r    r!   r   r   r	   Útest_async_gen_syntax_04L   s    z+AsyncGenSyntaxTest.test_async_gen_syntax_04c          	   C   s,   d}|   td¡ t|i i ƒ W d Q R X d S )NzWasync def foo():
            if 0:
                yield
            return 12
        zreturn.*value.*async gen)r   r   r   )r    r!   r   r   r	   Útest_async_gen_syntax_05U   s    z+AsyncGenSyntaxTest.test_async_gen_syntax_05N)r   r   r   r"   r#   r$   r%   r&   r   r   r   r	   r   /   s
   	
	r   c               @   sl   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S )ÚAsyncGenTestc             C   s0   dd„ }dd„ }||ƒ}||ƒ}|   ||¡ |S )Nc          
   S   st   g }xjy|  |  ¡ ¡ W q tk
r8   |  d¡ P Y q tk
rj } z|  tt|ƒƒ¡ W d d }~X Y qX qW |S )NÚSTOP)r   Ú__next__r   Ú	ExceptionÚstrÚtype)Úgr   r   r   r   r	   Úsync_iteratec   s    
(z5AsyncGenTest.compare_generators.<locals>.sync_iteratec          
   S   s¶   g }x¬y|   ¡  ¡  W q tk
r6   | d¡ P Y q tk
rz } z(|jr^| |jd ¡ n| d¡ P W d d }~X Y q tk
r¬ } z| tt|ƒƒ¡ W d d }~X Y qX qW |S )Nr(   r   zEMPTY StopIteration)	Ú	__anext__r)   r   r   r   r   r*   r+   r,   )r-   r   r   r   r   r	   Úasync_iterateo   s    

(z6AsyncGenTest.compare_generators.<locals>.async_iterate)ÚassertEqual)r    Úsync_genÚ	async_genr.   r0   Zsync_gen_resultZasync_gen_resultr   r   r	   Úcompare_generatorsb   s    zAsyncGenTest.compare_generatorsc                s(   ‡ fdd„}ˆ   t|ƒ ƒdddg¡ d S )Nc                sF   t ƒ I d H  dV } ˆ  | d ¡ t ƒ I d H  dV  t ƒ I d H  dV  d S )Né{   iÈ  i  )r   ZassertIs)Úa)r    r   r	   r   ‡   s    z5AsyncGenTest.test_async_gen_iteration_01.<locals>.genr5   iÈ  i  )r1   r   )r    r   r   )r    r	   Útest_async_gen_iteration_01†   s    	z(AsyncGenTest.test_async_gen_iteration_01c          
   C   sÜ   dd„ }|ƒ }|  ¡ }|  | ¡  ¡ d¡ y| ¡  ¡  W n4 tk
rn } z|  |jd d¡ W d d }~X Y nX |  d¡ |  | ¡  ¡ d¡ y| ¡  ¡  W n. tk
rÌ } z|  |j¡ W d d }~X Y nX |  d¡ d S )Nc               S  s"   t ƒ I d H  dV  t ƒ I d H  d S )Nr5   )r   r   r   r   r	   r   “   s    z5AsyncGenTest.test_async_gen_iteration_02.<locals>.gen)r   r   r5   zStopIteration was not raisedz!StopAsyncIteration was not raised)	Ú	__aiter__r1   r/   r)   r   r   Úfailr   ÚassertFalse)r    r   r-   Úair   r   r   r	   Útest_async_gen_iteration_02’   s    $
z(AsyncGenTest.test_async_gen_iteration_02c          	   C   s,   dd„ }|   t¡ t|ƒ ƒ W d Q R X d S )Nc               S  s,   t ƒ I d H  dV  t ddI d H  dV  d S )Nr5   T)r
   iÈ  )r   r   r   r   r	   r   ­   s    z5AsyncGenTest.test_async_gen_exception_03.<locals>.gen)ÚassertRaisesr   r   )r    r   r   r   r	   Útest_async_gen_exception_03¬   s    z(AsyncGenTest.test_async_gen_exception_03c          
   C   s    dd„ }|ƒ }|  ¡ }|  | ¡  ¡ d¡ y| ¡  ¡  W n4 tk
rn } z|  |jd d¡ W d d }~X Y nX |  d¡ |  t¡ | ¡  ¡  W d Q R X d S )Nc               S  s   t ƒ I d H  dV  dd  d S )Nr5   é   r   )r   r   r   r   r	   r   ·   s    z5AsyncGenTest.test_async_gen_exception_04.<locals>.gen)r   r   r5   zStopIteration was not raised)	r8   r1   r/   r)   r   r   r9   r=   ÚZeroDivisionError)r    r   r-   r;   r   r   r   r	   Útest_async_gen_exception_04¶   s    $
z(AsyncGenTest.test_async_gen_exception_04c          	   C   s.   dd„ }|   td¡ t|ƒ ƒ W d Q R X d S )Nc               S  s   dV  t ‚d S )Nr5   )r   r   r   r   r	   r   Ë   s    z5AsyncGenTest.test_async_gen_exception_05.<locals>.genz#async generator.*StopAsyncIteration)r   ÚRuntimeErrorr   )r    r   r   r   r	   Útest_async_gen_exception_05Ê   s    z(AsyncGenTest.test_async_gen_exception_05c          	   C   s.   dd„ }|   td¡ t|ƒ ƒ W d Q R X d S )Nc               S  s   dV  t ‚d S )Nr5   )r   r   r   r   r	   r   Ô   s    z5AsyncGenTest.test_async_gen_exception_06.<locals>.genzasync generator.*StopIteration)r   rB   r   )r    r   r   r   r	   Útest_async_gen_exception_06Ó   s    z(AsyncGenTest.test_async_gen_exception_06c             C   s$   dd„ }dd„ }|   |ƒ |ƒ ¡ d S )Nc               s   s,   zdV  dd  W d dV  dV  X dV  d S )Nr?   r   é   é   éd   r   r   r   r   r	   r2   Ý   s    z:AsyncGenTest.test_async_gen_exception_07.<locals>.sync_genc               S  s,   zdV  dd  W d dV  dV  X dV  d S )Nr?   r   rE   rF   rG   r   r   r   r   r	   r3   ç   s    z;AsyncGenTest.test_async_gen_exception_07.<locals>.async_gen)r4   )r    r2   r3   r   r   r	   Útest_async_gen_exception_07Ü   s    

z(AsyncGenTest.test_async_gen_exception_07c             C   s$   dd„ }dd„ }|   |ƒ |ƒ ¡ d S )Nc               s   s,   z
dV  W d dV  dd  dV  X dV  d S )Nr?   rE   r   rF   rG   r   r   r   r   r	   r2   ô   s    
z:AsyncGenTest.test_async_gen_exception_08.<locals>.sync_genc               S  sD   zdV  t ƒ I d H  W d t ƒ I d H  dV  dd  dV  X dV  d S )Nr?   rE   r   rF   rG   )r   r   r   r   r	   r3   þ   s    z;AsyncGenTest.test_async_gen_exception_08.<locals>.async_gen)r4   )r    r2   r3   r   r   r	   Útest_async_gen_exception_08ó   s    
z(AsyncGenTest.test_async_gen_exception_08c             C   s$   dd„ }dd„ }|   |ƒ |ƒ ¡ d S )Nc               s   s,   zdV  dd  W d dV  dV  X dV  d S )Nr?   r   rE   rF   rG   r   r   r   r   r	   r2     s    z:AsyncGenTest.test_async_gen_exception_09.<locals>.sync_genc               S  sD   zt ƒ I d H  dV  dd  W d dV  t ƒ I d H  dV  X dV  d S )Nr?   r   rE   rF   rG   )r   r   r   r   r	   r3     s    z;AsyncGenTest.test_async_gen_exception_09.<locals>.async_gen)r4   )r    r2   r3   r   r   r	   Útest_async_gen_exception_09  s    
z(AsyncGenTest.test_async_gen_exception_09c          	   C   s4   dd„ }|   td¡ |ƒ  ¡  d¡ W d Q R X d S )Nc               S  s
   dV  d S )Nr5   r   r   r   r   r	   r   &  s    z5AsyncGenTest.test_async_gen_exception_10.<locals>.genz!non-None value .* async generatorrG   )r   Ú	TypeErrorr/   r   )r    r   r   r   r	   Útest_async_gen_exception_10%  s    z(AsyncGenTest.test_async_gen_exception_10c             C   s¢   dd„ }|ƒ }|   |jd¡ d|_|   |jd¡ |  d|j¡ d|_|   |jd¡ |  |j¡ |  |jtj	¡ |  
|j¡ |  |jtj¡ |  t | ¡ ¡¡ d S )Nc               S  s
   dV  d S )Nr5   r   r   r   r   r	   r   -  s    z/AsyncGenTest.test_async_gen_api_01.<locals>.genr   Z123z.gen)r1   r   ÚassertInr   ZassertIsNoneÚag_awaitÚassertIsInstanceÚag_frameÚtypesÚ	FrameTyper:   Ú
ag_runningÚag_codeÚCodeTypeZ
assertTrueÚinspectZisawaitableÚaclose)r    r   r-   r   r   r	   Útest_async_gen_api_01,  s    z"AsyncGenTest.test_async_gen_api_01N)r   r   r   r4   r7   r<   r>   rA   rC   rD   rH   rI   rJ   rL   rX   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;S )<ÚAsyncGenAsyncioTestc             C   s   t  ¡ | _t  d ¡ d S )N)r   Znew_event_loopÚloopZset_event_loop)r    r   r   r	   ÚsetUpD  s    
zAsyncGenAsyncioTest.setUpc             C   s   | j  ¡  d | _ d S )N)rZ   Úclose)r    r   r   r	   ÚtearDownH  s    
zAsyncGenAsyncioTest.tearDownc          	   Ã   s>   g }x4|2 y3 d H }W n
 t k
s.X | |¡ q
   Y  W |S )N)r   r   )r    r   r   r   r   r   r	   r   L  s    zAsyncGenAsyncioTest.to_listc                s4   ‡ fdd„}ˆ j  ˆ  |ƒ ¡¡}ˆ  |ddg¡ d S )Nc                 s<   dV  t jdˆ jdI d H  dV  t jdˆ jdI d H  d S )Nr?   g{®Gáz„?)rZ   rE   rF   )r   ÚsleeprZ   r   )r    r   r	   r   S  s    z:AsyncGenAsyncioTest.test_async_gen_asyncio_01.<locals>.genr?   rE   )rZ   r   r   r1   )r    r   r   r   )r    r	   Útest_async_gen_asyncio_01R  s    z-AsyncGenAsyncioTest.test_async_gen_asyncio_01c          	      s:   ‡ fdd„}ˆ   t¡ ˆ j ˆ  |ƒ ¡¡ W d Q R X d S )Nc                 s4   dV  t jdˆ jdI d H  dV  dd  dV  d S )Nr?   g{®Gáz„?)rZ   rE   r   rF   )r   r^   rZ   r   )r    r   r	   r   _  s
    z:AsyncGenAsyncioTest.test_async_gen_asyncio_02.<locals>.gen)r=   r@   rZ   r   r   )r    r   r   )r    r	   Útest_async_gen_asyncio_02^  s    z-AsyncGenAsyncioTest.test_async_gen_asyncio_02c                s>   | j ‰ G ‡ fdd„dƒ}ˆ  |  |ƒ ¡¡}|  |ddg¡ d S )Nc                   s   e Zd Z‡ fdd„ZdS )z:AsyncGenAsyncioTest.test_async_gen_asyncio_03.<locals>.Genc               s$   dV  t jdˆ dI d H  dV  d S )Nr?   g{®Gáz„?)rZ   rE   )r   r^   )r    )rZ   r   r	   r8   m  s    zDAsyncGenAsyncioTest.test_async_gen_asyncio_03.<locals>.Gen.__aiter__N)r   r   r   r8   r   )rZ   r   r	   ÚGenl  s   ra   r?   rE   )rZ   r   r   r1   )r    ra   r   r   )rZ   r	   Útest_async_gen_asyncio_03i  s    z-AsyncGenAsyncioTest.test_async_gen_asyncio_03c                sH   ‡fdd„‰ ‡ ‡fdd„}‡ ‡fdd„}ˆj  |ƒ ¡ ˆj  |ƒ ¡ d S )Nc                 sh   dV  t jdˆ jdI d H  ydV  dV  W n tk
rF   dV  Y nX t jdˆ jdI d H  dV  d S )Nr?   g{®Gáz„?)rZ   rE   rF   iè  é   )r   r^   rZ   r@   r   )r    r   r	   Úfoov  s    
z@AsyncGenAsyncioTest.test_async_gen_asyncio_anext_04.<locals>.fooc           	   “   s®   ˆ ƒ   ¡ } ˆ |  ¡ I d H d¡ ˆ |  ¡ I d H d¡ ˆ |  ¡ I d H d¡ ˆ |  ¡ I d H d¡ ˆ t¡ |  ¡ I d H  W d Q R X ˆ t¡ |  ¡ I d H  W d Q R X d S )Nr?   rE   rF   rc   )r8   r1   r/   r=   r   )Úit)rd   r    r   r	   Úrun1  s    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_anext_04.<locals>.run1c           
   “   sÆ   ˆ ƒ   ¡ } ˆ |  ¡ I d H d¡ ˆ |  ¡ I d H d¡ y|  ¡  t¡ W n4 tk
r| } zˆ |jd d¡ W d d }~X Y nX ˆ d¡ ˆ |  ¡ I d H d¡ ˆ t	¡ |  ¡ I d H  W d Q R X d S )Nr?   rE   r   iè  zStopIteration was not raisedrc   )
r8   r1   r/   r
   r@   r   r   r9   r=   r   )re   r   )rd   r    r   r	   Úrun2  s    
$
zAAsyncGenAsyncioTest.test_async_gen_asyncio_anext_04.<locals>.run2)rZ   r   )r    rf   rg   r   )rd   r    r	   Útest_async_gen_asyncio_anext_04u  s
    z3AsyncGenAsyncioTest.test_async_gen_asyncio_anext_04c                s(   dd„ ‰ ‡ ‡fdd„}ˆj  |ƒ ¡ d S )Nc              S  s   dV } | V } | d V  d S )Nr?   rG   r   )Úvr   r   r	   rd      s    z@AsyncGenAsyncioTest.test_async_gen_asyncio_anext_05.<locals>.fooc           
   “   s(  ˆ ƒ   ¡ } y|  ¡  d ¡ W n4 tk
rP } zˆ |jd d¡ W d d }~X Y nX ˆ d¡ y|  ¡  d¡ W n4 tk
r¢ } zˆ |jd d¡ W d d }~X Y nX ˆ d¡ y|  ¡  d¡ W n4 tk
rô } zˆ |jd d¡ W d d }~X Y nX ˆ d¡ ˆ t¡ |  ¡ I d H  W d Q R X d S )Nr   r?   zStopIteration was not raisedé
   é   i°  )	r8   r/   r   r   r1   r   r9   r=   r   )re   r   )rd   r    r   r	   Úrun¥  s$    
$
$
$
z@AsyncGenAsyncioTest.test_async_gen_asyncio_anext_05.<locals>.run)rZ   r   )r    rl   r   )rd   r    r	   Útest_async_gen_asyncio_anext_05Ÿ  s    z3AsyncGenAsyncioTest.test_async_gen_asyncio_anext_05c          	      sv   d‰ dd„ }|ƒ }|  d ¡ ˆ t¡ |  d ¡ W d Q R X ‡ fdd„‰‡ ‡‡fdd„}ˆj |ƒ ¡ ˆ ˆ d¡ d S )	Nr   c               s   s   y
d V  W n   Y nX d S )Nr   r   r   r   r	   rd   Æ  s    
z@AsyncGenAsyncioTest.test_async_gen_asyncio_anext_06.<locals>.fooc                 s    y
d V  W n   Y nX d‰ d S )Nr?   r   r   )ÚDONEr   r	   r   Ò  s
    
z@AsyncGenAsyncioTest.test_async_gen_asyncio_anext_06.<locals>.genc           	   “   sH   ˆƒ } |   d ¡I d H  ˆ t¡ |   d ¡I d H  W d Q R X ˆ d7 ‰ d S )Nrj   )Úasendr=   r   )r-   )rn   r   r    r   r	   rl   Ú  s
    z@AsyncGenAsyncioTest.test_async_gen_asyncio_anext_06.<locals>.runé   )r   r=   r   rZ   r   r1   )r    rd   r-   rl   r   )rn   r   r    r	   Útest_async_gen_asyncio_anext_06Â  s    
z3AsyncGenAsyncioTest.test_async_gen_asyncio_anext_06c                s(   dd„ ‰ ‡ ‡fdd„}ˆj  |ƒ ¡ d S )Nc               S  s*   y
dV  W n t k
r$   dV  Y nX d S )N)r?   )rE   )r@   r   r   r   r	   rd   æ  s    
zCAsyncGenAsyncioTest.test_async_gen_asyncio_anext_tuple.<locals>.fooc           	   “   s€   ˆ ƒ   ¡ } ˆ |  ¡ I d H d¡ ˆ t¡}|  ¡  t¡ W d Q R X ˆ |jjd d¡ ˆ t	¡ |  ¡ I d H  W d Q R X d S )N)r?   r   )rE   )
r8   r1   r/   r=   r   r
   r@   Ú	exceptionr   r   )re   Úcm)rd   r    r   r	   rl   ì  s    
zCAsyncGenAsyncioTest.test_async_gen_asyncio_anext_tuple.<locals>.run)rZ   r   )r    rl   r   )rd   r    r	   Ú"test_async_gen_asyncio_anext_tupleå  s    
z6AsyncGenAsyncioTest.test_async_gen_asyncio_anext_tuplec                s(   dd„ ‰ ‡ ‡fdd„}ˆj  |ƒ ¡ d S )Nc               S  s2   yt dƒV  W n tk
r,   t dƒV  Y nX d S )Nr?   rF   )r   r@   r   r   r   r	   rd   ù  s    zKAsyncGenAsyncioTest.test_async_gen_asyncio_anext_stopiteration.<locals>.fooc           	   “   s¤   ˆ ƒ   ¡ } |  ¡ I d H }ˆ |t¡ ˆ |jd¡ ˆ t¡}|  ¡  t¡ W d Q R X |j	j
d }ˆ |t¡ ˆ |jd¡ ˆ t¡ |  ¡ I d H  W d Q R X d S )Nr?   r   rF   )r8   r/   rO   r   r1   Úvaluer=   r
   r@   rr   r   r   )re   ri   rs   )rd   r    r   r	   rl   ÿ  s    
zKAsyncGenAsyncioTest.test_async_gen_asyncio_anext_stopiteration.<locals>.run)rZ   r   )r    rl   r   )rd   r    r	   Ú*test_async_gen_asyncio_anext_stopiterationø  s    z>AsyncGenAsyncioTest.test_async_gen_asyncio_anext_stopiterationc          	      sB   ‡fdd„‰ ‡ fdd„}ˆ  td¡ ˆj |ƒ ¡ W d Q R X d S )Nc            
     s6   zdV  dd  W d t jdˆ jdI d H  dV  X d S )Nr?   r   g{®Gáz„?)rZ   rk   )r   r^   rZ   r   )r    r   r	   rd     s
    zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_06.<locals>.fooc              “   s.   ˆ ƒ } |   ¡ }| ¡ I d H  |  ¡ I d H  d S )N)r8   r/   rW   )r   re   )rd   r   r	   rl     s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_06.<locals>.runz%async generator ignored GeneratorExit)r   rB   rZ   r   )r    rl   r   )rd   r    r	   Ú test_async_gen_asyncio_aclose_06  s    z4AsyncGenAsyncioTest.test_async_gen_asyncio_aclose_06c                s<   d‰ ‡ ‡fdd„‰‡fdd„}ˆj  |ƒ ¡ ˆ ˆ d¡ d S )Nr   c            
     sV   zdV  dd  W d t jdˆjdI d H  t jdˆjdI d H  ˆ d7 ‰ X ˆ d7 ‰ d S )Nr?   r   g{®Gáz„?)rZ   iè  )r   r^   rZ   r   )rn   r    r   r	   rd   &  s    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_07.<locals>.fooc              “   s.   ˆ ƒ } |   ¡ }| ¡ I d H  |  ¡ I d H  d S )N)r8   r/   rW   )r   re   )rd   r   r	   rl   1  s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_07.<locals>.runr?   )rZ   r   r1   )r    rl   r   )rn   rd   r    r	   Ú test_async_gen_asyncio_aclose_07#  s
    z4AsyncGenAsyncioTest.test_async_gen_asyncio_aclose_07c                sv   d‰ t jˆjd‰‡ ‡‡fdd„‰‡‡fdd„}ˆj |ƒ ¡}ˆ ˆ d¡ ˆ ¡  | ¡  ˆj t jdˆjd¡ d S )	Nr   )rZ   c            
     sf   z"dV  ˆI d H  ˆ d7 ‰ dV  W d t jdˆjdI d H  t jdˆjdI d H  ˆ d7 ‰ X ˆ d7 ‰ d S )Nr?   iè  rE   g{®Gáz„?)rZ   )r   r^   rZ   r   )rn   r   r    r   r	   rd   ?  s    


zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_08.<locals>.fooc              “   s\   ˆ ƒ } |   ¡ }ˆ | ¡ I d H d¡ ˆj | ¡ ¡}tjdˆjdI d H  |  ¡ I d H  |S )Nr?   g{®Gáz„?)rZ   )r8   r1   r/   rZ   Úcreate_taskr   r^   rW   )r   re   Út)rd   r    r   r	   rl   L  s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_08.<locals>.runr?   g{®Gáz„?)r   ZFuturerZ   r   r1   Úcancelr^   )r    rl   rz   r   )rn   rd   r   r    r	   Ú test_async_gen_asyncio_aclose_08:  s    	z4AsyncGenAsyncioTest.test_async_gen_asyncio_aclose_08c                s>   d‰ ‡ ‡fdd„‰‡‡fdd„}ˆj  |ƒ ¡ ˆ ˆ d¡ d S )Nr   c            
     sH   zx
dV  qW W d t jdˆjdI d H  t jdˆjdI d H  d‰ X d S )Nr?   g{®Gáz„?)rZ   )r   r^   rZ   r   )rn   r    r   r	   r   `  s    zDAsyncGenAsyncioTest.test_async_gen_asyncio_gc_aclose_09.<locals>.genc              “   s>   ˆ ƒ } |   ¡ I d H  |   ¡ I d H  ~ tjdˆjdI d H  d S )Ngš™™™™™¹?)rZ   )r/   r   r^   rZ   )r-   )r   r    r   r	   rl   j  s
    zDAsyncGenAsyncioTest.test_async_gen_asyncio_gc_aclose_09.<locals>.runr?   )rZ   r   r1   )r    rl   r   )rn   r   r    r	   Ú#test_async_gen_asyncio_gc_aclose_09]  s
    
z7AsyncGenAsyncioTest.test_async_gen_asyncio_gc_aclose_09c                s\   d‰ dd„ }|ƒ }|  d ¡ | ¡  ‡ fdd„‰‡ ‡fdd„}| j |ƒ ¡ |  ˆ d¡ d S )	Nr   c               s   s   y
d V  W n   Y nX d S )Nr   r   r   r   r	   rd   y  s    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_10.<locals>.fooc                 s    y
d V  W n   Y nX d‰ d S )Nr?   r   r   )rn   r   r	   r   „  s
    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_10.<locals>.genc              “   s0   ˆƒ } |   d ¡I d H  |  ¡ I d H  ˆ d7 ‰ d S )Nrj   )ro   rW   )r-   )rn   r   r   r	   rl   Œ  s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_10.<locals>.runrp   )r   r\   rZ   r   r1   )r    rd   r-   rl   r   )rn   r   r	   Ú test_async_gen_asyncio_aclose_10u  s    
z4AsyncGenAsyncioTest.test_async_gen_asyncio_aclose_10c          	      sv   d‰ dd„ }|ƒ }|  d ¡ ˆ td¡ | ¡  W d Q R X ‡ fdd„‰‡ ‡‡fdd„}ˆj |ƒ ¡ ˆ ˆ d	¡ d S )
Nr   c               s   s"   y
d V  W n   Y nX d V  d S )Nr   r   r   r   r	   rd   š  s
    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_11.<locals>.foozignored GeneratorExitc                 s*   y
d V  W n   Y nX d V  ˆ d7 ‰ d S )Nr?   r   r   )rn   r   r	   r   §  s    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_11.<locals>.genc           	   “   sH   ˆƒ } |   d ¡I d H  ˆ td¡ |  ¡ I d H  W d Q R X ˆ d7 ‰ d S )Nzignored GeneratorExitrj   )ro   r   rB   rW   )r-   )rn   r   r    r   r	   rl   °  s
    zAAsyncGenAsyncioTest.test_async_gen_asyncio_aclose_11.<locals>.runrj   )r   r   rB   r\   rZ   r   r1   )r    rd   r-   rl   r   )rn   r   r    r	   Ú test_async_gen_asyncio_aclose_11–  s    
	z4AsyncGenAsyncioTest.test_async_gen_asyncio_aclose_11c                sx   d‰ dd„ }|ƒ }|  d ¡}ˆ |d¡ |  d¡}ˆ |d¡ ‡ ‡fdd„‰‡‡fd	d
„}ˆj |ƒ ¡ ˆ ˆ d¡ d S )Nr   c              s   s   dV } | d V  d S )Nr?   rE   r   )ri   r   r   r	   Úsgen¿  s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_asend_01.<locals>.sgenr?   rG   éÈ   c           
     sŽ   zVt jdˆjdI d H  dV } t jdˆjdI d H  | d V  t jdˆjdI d H  d S t jdˆjdI d H  t jdˆjdI d H  d‰ X d S )Ng{®Gáz„?)rZ   r?   rE   )r   r^   rZ   )ri   )rn   r    r   r	   r   È  s    
z@AsyncGenAsyncioTest.test_async_gen_asyncio_asend_01.<locals>.genc           	   “   sh   ˆ ƒ } |   d ¡I d H }ˆ |d¡ |   d¡I d H }ˆ |d¡ ˆ t¡ |   d ¡I d H  W d Q R X d S )Nr?   rG   r   )ro   r1   r=   r   )r-   ri   )r   r    r   r	   rl   Ö  s    z@AsyncGenAsyncioTest.test_async_gen_asyncio_asend_01.<locals>.run)r   r1   rZ   r   )r    r€   Úsgri   rl   r   )rn   r   r    r	   Útest_async_gen_asyncio_asend_01»  s    

z3AsyncGenAsyncioTest.test_async_gen_asyncio_asend_01c          	      sb   d‰ ‡fdd„‰‡ ‡‡fdd„‰‡‡fdd„}ˆ  t¡ ˆj |ƒ ¡ W d Q R X ˆ ˆ d¡ d S )	Nr   c             “   s"   t j| ˆ jdI d H  dd  d S )N)rZ   r?   r   )r   r^   rZ   )Údelay)r    r   r	   Úsleep_n_crashè  s    zJAsyncGenAsyncioTest.test_async_gen_asyncio_asend_02.<locals>.sleep_n_crashc           
     sx   z@t jdˆjdI d H  dV } ˆdƒI d H  ˆ d7 ‰ | d V  W d t jdˆjdI d H  t jdˆjdI d H  d‰ X d S )Ng{®Gáz„?)rZ   r?   iè  rE   )r   r^   rZ   )ri   )rn   r    r…   r   r	   r   ì  s    z@AsyncGenAsyncioTest.test_async_gen_asyncio_asend_02.<locals>.genc              “   s6   ˆ ƒ } |   d ¡I d H }ˆ |d¡ |   d¡I d H  d S )Nr?   rG   )ro   r1   )r-   ri   )r   r    r   r	   rl   ù  s    z@AsyncGenAsyncioTest.test_async_gen_asyncio_asend_02.<locals>.runr?   )r=   r@   rZ   r   r1   )r    rl   r   )rn   r   r    r…   r	   Útest_async_gen_asyncio_asend_02å  s    z3AsyncGenAsyncioTest.test_async_gen_asyncio_asend_02c          	      sd   d‰ ‡fdd„‰‡ ‡‡fdd„‰‡‡fdd„}ˆ  tj¡ ˆj |ƒ ¡ W d Q R X ˆ ˆ d¡ d S )	Nr   c             “   s@   t jt j| ˆjdˆjd‰ ˆj | d ‡ fdd„¡ ˆ I d H S )N)rZ   rE   c                  s   ˆ   ¡ S )N)r{   r   )r   r   r	   Ú<lambda>  ó    z\AsyncGenAsyncioTest.test_async_gen_asyncio_asend_03.<locals>.sleep_n_crash.<locals>.<lambda>)r   Úensure_futurer^   rZ   Ú
call_later)r„   )r    )r   r	   r…     s    
zJAsyncGenAsyncioTest.test_async_gen_asyncio_asend_03.<locals>.sleep_n_crashc           
     sx   z@t jdˆjdI d H  dV } ˆdƒI d H  ˆ d7 ‰ | d V  W d t jdˆjdI d H  t jdˆjdI d H  d‰ X d S )Ng{®Gáz„?)rZ   r?   iè  rE   )r   r^   rZ   )ri   )rn   r    r…   r   r	   r     s    z@AsyncGenAsyncioTest.test_async_gen_asyncio_asend_03.<locals>.genc              “   s6   ˆ ƒ } |   d ¡I d H }ˆ |d¡ |   d¡I d H  d S )Nr?   rG   )ro   r1   )r-   ri   )r   r    r   r	   rl     s    z@AsyncGenAsyncioTest.test_async_gen_asyncio_asend_03.<locals>.runr?   )r=   r   ÚCancelledErrorrZ   r   r1   )r    rl   r   )rn   r   r    r…   r	   Útest_async_gen_asyncio_asend_03  s    z3AsyncGenAsyncioTest.test_async_gen_asyncio_asend_03c          	      s°   d‰ G dd„ dt ƒ‰‡fdd„}|ƒ }| d ¡}ˆ |d¡ | ˆ¡}ˆ |d¡ ˆ t¡ | d ¡ W d Q R X ‡ ‡‡fdd	„‰‡‡‡fd
d„}ˆj |ƒ ¡ ˆ ˆ d¡ d S )Nr   c               @   s   e Zd ZdS )zCAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_01.<locals>.FooErN)r   r   r   r   r   r   r	   ÚFooEr*  s   r   c              3   s2   y
dV } W n ˆ k
r"   d} Y nX | d V  d S )Nr?   iè  rE   r   )ri   )r   r   r	   r€   .  s
    

zBAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_01.<locals>.sgenr?   iÐ  c           
     s¬   ztt jdˆjdI d H  y
dV } W n. ˆk
rP   d} t jdˆjdI d H  Y nX | d V  t jdˆjdI d H  W d t jdˆjdI d H  t jdˆjdI d H  d‰ X d S )Ng{®Gáz„?)rZ   r?   iè  rE   )r   r^   rZ   )ri   )rn   r   r    r   r	   r   <  s    

zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_01.<locals>.genc           	   “   sh   ˆƒ } |   d ¡I d H }ˆ |d¡ |  ˆ ¡I d H }ˆ |d¡ ˆ t¡ |   d ¡I d H  W d Q R X d S )Nr?   iÐ  )ro   r1   Úathrowr=   r   )r-   ri   )r   r   r    r   r	   rl   M  s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_01.<locals>.run)r*   r   r1   r
   r=   r   rZ   r   )r    r€   r‚   ri   rl   r   )rn   r   r   r    r	   Ú test_async_gen_asyncio_athrow_01'  s    

z4AsyncGenAsyncioTest.test_async_gen_asyncio_athrow_01c          	      sz   d‰ G dd„ dt ƒ‰‡fdd„‰‡ ‡‡‡fdd„‰‡ ‡‡‡fdd	„}ˆ tj¡ ˆj |ƒ ¡ W d Q R X ˆ ˆ d
¡ d S )Nr   c               @   s   e Zd ZdS )zCAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_02.<locals>.FooErN)r   r   r   r   r   r   r	   r   _  s   r   c             “   s@   t jt j| ˆjdˆjd‰ ˆj | d ‡ fdd„¡ ˆ I d H S )N)rZ   rE   c                  s   ˆ   ¡ S )N)r{   r   )r   r   r	   r‡   e  rˆ   z]AsyncGenAsyncioTest.test_async_gen_asyncio_athrow_02.<locals>.sleep_n_crash.<locals>.<lambda>)r   r‰   r^   rZ   rŠ   )r„   )r    )r   r	   r…   b  s    
zKAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_02.<locals>.sleep_n_crashc           
     s    zht jdˆjdI d H  y
dV } W n" ˆk
rD   ˆdƒI d H  Y nX | d V  t jdˆjdI d H  W d t jdˆjdI d H  t jdˆjdI d H  d‰ X d S )Ng{®Gáz„?)rZ   r?   rE   )r   r^   rZ   )ri   )rn   r   r    r…   r   r	   r   h  s    

zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_02.<locals>.genc              “   sj   ˆƒ } |   d ¡I d H }ˆ |d¡ y|  ˆ¡I d H  W n$ tjk
rZ   ˆ ˆ d¡ ‚ Y nX ˆ d¡ d S )Nr?   zCancelledError was not raised)ro   r1   rŽ   r   r‹   r9   )r-   ri   )rn   r   r   r    r   r	   rl   x  s    zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_02.<locals>.runr?   )r*   r=   r   r‹   rZ   r   r1   )r    rl   r   )rn   r   r   r    r…   r	   Ú test_async_gen_asyncio_athrow_02\  s    z4AsyncGenAsyncioTest.test_async_gen_asyncio_athrow_02c          	      sv   d‰ dd„ }|ƒ }|  d ¡ ˆ t¡ | t¡ W d Q R X ‡ fdd„‰‡ ‡‡fdd„}ˆj |ƒ ¡ ˆ ˆ d¡ d S )	Nr   c               s   s   y
d V  W n   Y nX d S )Nr   r   r   r   r	   rd   Ž  s    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_03.<locals>.fooc                 s    y
d V  W n   Y nX d‰ d S )Nr?   r   r   )rn   r   r	   r   š  s
    
zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_03.<locals>.genc           	   “   sH   ˆƒ } |   d ¡I d H  ˆ t¡ |  t¡I d H  W d Q R X ˆ d7 ‰ d S )Nrj   )ro   r=   r   rŽ   Ú
ValueError)r-   )rn   r   r    r   r	   rl   ¢  s
    zAAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_03.<locals>.runrp   )r   r=   r   r
   r‘   rZ   r   r1   )r    rd   r-   rl   r   )rn   r   r    r	   Ú test_async_gen_asyncio_athrow_03Š  s    
z4AsyncGenAsyncioTest.test_async_gen_asyncio_athrow_03c                s(   dd„ ‰ ‡ ‡fdd„}ˆj  |ƒ ¡ d S )Nc               S  s*   y
dV  W n t k
r$   dV  Y nX d S )Nr?   )rE   )r@   r   r   r   r	   r   ®  s    
zDAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_tuple.<locals>.genc           	   “   sh   ˆ ƒ } |   d ¡I d H }ˆ |d¡ |  t¡I d H }ˆ |d¡ ˆ t¡ |   d ¡I d H  W d Q R X d S )Nr?   )rE   )ro   r1   rŽ   r@   r=   r   )r-   ri   )r   r    r   r	   rl   ´  s    zDAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_tuple.<locals>.run)rZ   r   )r    rl   r   )r   r    r	   Ú#test_async_gen_asyncio_athrow_tuple­  s    	z7AsyncGenAsyncioTest.test_async_gen_asyncio_athrow_tuplec                s(   dd„ ‰ ‡ ‡fdd„}ˆj  |ƒ ¡ d S )Nc               S  s.   y
dV  W n t k
r(   tdƒV  Y nX d S )Nr?   rE   )r@   r   r   r   r   r	   r   À  s    
zLAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_stopiteration.<locals>.genc           	   “   sv   ˆ ƒ } |   d ¡I d H }ˆ |d¡ |  t¡I d H }ˆ |t¡ ˆ |jd¡ ˆ t¡ |   d ¡I d H  W d Q R X d S )Nr?   rE   )	ro   r1   rŽ   r@   rO   r   ru   r=   r   )r-   ri   )r   r    r   r	   rl   Æ  s    zLAsyncGenAsyncioTest.test_async_gen_asyncio_athrow_stopiteration.<locals>.run)rZ   r   )r    rl   r   )r   r    r	   Ú+test_async_gen_asyncio_athrow_stopiteration¿  s    
z?AsyncGenAsyncioTest.test_async_gen_asyncio_athrow_stopiterationc                sœ   d‰ ‡ ‡fdd„‰‡fdd„}ˆj  |ƒ ¡}ˆj  |ƒ ¡}ˆj  tjdˆj d¡ ˆj  ˆj  ¡ ¡ ˆ ˆ d¡ | ¡  | ¡  ˆj  tjdˆj d¡ d S )	Nr   c          
     sF   z t j| ˆjdI d H  dV  W d t jdˆjdI d H  ˆ d7 ‰ X d S )N)rZ   r?   r   )r   r^   rZ   )Útimeout)Ú	finalizedr    r   r	   ÚwaiterÕ  s
    
zFAsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_01.<locals>.waiterc           	   “   s4   x.ˆ dƒ2 y3 d H } W q
 t k
s$X q
   Y  W d S )Nr?   )r   )Ú_)r—   r   r	   ÚwaitÞ  s    "zDAsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_01.<locals>.waitgš™™™™™¹?)rZ   rE   )rZ   ry   r   r   r^   Úshutdown_asyncgensr1   r{   )r    r™   Zt1Zt2r   )r–   r    r—   r	   Ú"test_async_gen_asyncio_shutdown_01Ò  s    	z6AsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_01c                sž   d‰ ‡ ‡fdd„}‡fdd„‰‡fdd„}ˆj  |ƒ ¡}ˆj  tjdˆj d	¡ ˆj  |¡ ˆj  ˆj  ¡ ¡ ˆ ˆ d
¡ | ¡  ˆj  tjdˆj d	¡ d S )Nr   c                s(   ˆ  d|¡ d}||d kr$ˆ d7 ‰ d S )NZasyncgenz0an error occurred during closing of asynchronousÚmessager?   )rM   )rZ   ÚcontextZexpected)Úloggedr    r   r	   Úloggerò  s    zFAsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_02.<locals>.loggerc               s0   z t j| ˆ jdI d H  dV  W d dd  X d S )N)rZ   r?   r   )r   r^   rZ   )r•   )r    r   r	   r—   ù  s    
zFAsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_02.<locals>.waiterc           	   “   s4   x.ˆ dƒ2 y3 d H } W q
 t k
s$X q
   Y  W d S )Nr?   )r   )r˜   )r—   r   r	   r™      s    "zDAsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_02.<locals>.waitgš™™™™™¹?)rZ   r?   )	rZ   ry   r   r   r^   Zset_exception_handlerrš   r1   r{   )r    rŸ   r™   rz   r   )rž   r    r—   r	   Ú"test_async_gen_asyncio_shutdown_02ï  s    z6AsyncGenAsyncioTest.test_async_gen_asyncio_shutdown_02c                sP   ‡fdd„‰ ‡ fdd„‰‡fdd„}ˆj  |ƒ ¡}ˆ |dd„ td	ƒD ƒ¡ d S )
Nc               s2   x,t | ƒD ] }tjdˆ jdI d H  |V  q
W d S )Ng{®Gáz„?)rZ   )Úranger   r^   rZ   )Únr   )r    r   r	   Úarange  s    z@AsyncGenAsyncioTest.test_async_gen_expression_01.<locals>.arangec                s   dd„ ˆ | ƒ2 ƒS )Nc          	   S  s4   | y3 d H }W n
 t k
s&X |d V  q   Y  d S )NrE   )r   )Ú.0r   r   r   r	   ú	<genexpr>  s   
 zXAsyncGenAsyncioTest.test_async_gen_expression_01.<locals>.make_arange.<locals>.<genexpr>r   )r¢   )r£   r   r	   Úmake_arange  s    zEAsyncGenAsyncioTest.test_async_gen_expression_01.<locals>.make_arangec               “   s   dd„ ˆ dƒ2 ƒI d H S )Nc          
   Ó   s.   g | y3 d H }W n
 t k
s"X |‘q   Y  S )N)r   )r¤   r   r   r   r	   ú
<listcomp>  s    zQAsyncGenAsyncioTest.test_async_gen_expression_01.<locals>.run.<locals>.<listcomp>rj   r   r   )r¦   r   r	   rl     s    z=AsyncGenAsyncioTest.test_async_gen_expression_01.<locals>.runc             S   s   g | ]}|d  ‘qS )rE   r   )r¤   r   r   r   r	   r§     s    zDAsyncGenAsyncioTest.test_async_gen_expression_01.<locals>.<listcomp>rj   )rZ   r   r1   r¡   )r    rl   r   r   )r£   r¦   r    r	   Útest_async_gen_expression_01  s
    z0AsyncGenAsyncioTest.test_async_gen_expression_01c                sR   ‡fdd„‰‡fdd„‰ ‡ fdd„}ˆj  |ƒ ¡}ˆ |dd„ td	d
ƒD ƒ¡ d S )Nc             “   s   t jdˆ jdI d H  | S )Ng{®Gáz„?)rZ   )r   r^   rZ   )r¢   )r    r   r	   Úwrap!  s    z>AsyncGenAsyncioTest.test_async_gen_expression_02.<locals>.wrapc                s   ‡ fdd„t | ƒD ƒS )Nc               s$   | ]}ˆ |ƒI d H r|d V  qd S )NrE   r   )r¤   r   )r©   r   r	   r¥   '  s    zXAsyncGenAsyncioTest.test_async_gen_expression_02.<locals>.make_arange.<locals>.<genexpr>)r¡   )r¢   )r©   r   r	   r¦   %  s    zEAsyncGenAsyncioTest.test_async_gen_expression_02.<locals>.make_arangec               “   s   dd„ ˆ dƒ2 ƒI d H S )Nc          
   Ó   s.   g | y3 d H }W n
 t k
s"X |‘q   Y  S )N)r   )r¤   r   r   r   r	   r§   *  s    zQAsyncGenAsyncioTest.test_async_gen_expression_02.<locals>.run.<locals>.<listcomp>rj   r   r   )r¦   r   r	   rl   )  s    z=AsyncGenAsyncioTest.test_async_gen_expression_02.<locals>.runc             S   s   g | ]}|d  ‘qS )rE   r   )r¤   r   r   r   r	   r§   -  s    zDAsyncGenAsyncioTest.test_async_gen_expression_02.<locals>.<listcomp>r?   rj   )rZ   r   r1   r¡   )r    rl   r   r   )r¦   r    r©   r	   Útest_async_gen_expression_02   s
    z0AsyncGenAsyncioTest.test_async_gen_expression_02N) r   r   r   r[   r]   r   r_   r`   rb   rh   rm   rq   rt   rv   rw   rx   r|   r}   r~   r   rƒ   r†   rŒ   r   r   r’   r“   r”   r›   r    r¨   rª   r   r   r   r	   rY   B  s:   *###!%* "5.#!rY   Ú__main__)rV   rQ   ZunittestZtest.supportr   r   r*   r   Ú	coroutiner   r   r   ZTestCaser   r'   rY   r   Úmainr   r   r   r	   Ú<module>   s(   
1 c     s