o
    ‡eù`  ã                   @   sp  d dl mZ d dlmZm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	Z	d dlmZ d dlmZ d dlmZ d dlmZ ejdd	„ ƒZG d
d„ dejƒZG dd„ deƒZG dd„ deƒZdCdd„Zdd„ Zd\ZZZG dd„ deƒZdZdZejr‡ej sŠej!sŠej"rŒdZG dd„ deƒZ#G dd„ de#ƒZ$ej%G dd „ d e#ƒƒZ&ej%G d!d"„ d"e#ƒƒZ'G d#d$„ d$eƒZ(G d%d&„ d&eƒZ)d'd(„ Z*G d)d*„ d*eƒZ+G d+d,„ d,eƒZ,G d-d.„ d.eƒZ-G d/d0„ d0eƒZ.G d1d2„ d2eƒZ/G d3d4„ d4eƒZ0d5d6„ Z1G d7d8„ d8eƒZ2d d9l	m3Z3 e 4e5e	j6d:ƒd;¡G d<d=„ d=eƒƒZ7G d>d?„ d?ejƒZ8G d@dA„ dAeƒZ9e:dBkr6e ;¡  dS dS )Dé    )Úprint_function)ÚtimeÚsleepN)Ú
ThreadPool)ÚInvalidThreadUseError©ÚExpectedException)ÚPYPYc                  c   s@    t  ¡ } t  ¡  zd V  W | rt  ¡  d S d S | rt  ¡  w w ©N)ÚgcÚ	isenabledÚdisableÚenable)Zwas_enabled© r   úMD:\Projects\ConvertPro\env\Lib\site-packages\gevent/tests/test__threadpool.pyÚdisabled_gc   s   €ÿ
ÿr   c                   @   s<   e Zd ZejZdZdZeZ	dd„ Z
ejfdd„Zdd„ ZdS )	ÚTestCaseNr   c                 C   s   | j S r
   )ÚClassUnderTest©Úselfr   r   r   Ú_FUT*   ó   zTestCase._FUTc                 C   s2   |   ¡ |ƒ | _}|  j|f7  _|r|| j_|S r
   )r   ÚpoolÚ
_all_poolsÚsize)r   ÚmaxsizeÚcreate_all_worker_threadsr   r   r   r   Ú_makeOne-   s
   zTestCase._makeOnec                 C   s`   d | _ | jd}| _|D ]}t|dd ƒpt|dƒ}|ƒ  ~qtjr,tdƒD ]}t ¡  q%d S d S )Nr   ÚkillÚshutdowné   )r   r   ÚgetattrÚ	greentestÚRUN_LEAKCHECKSÚranger   Úcollect)r   Z	all_poolsr   r   Ú_r   r   r   Úcleanup5   s   
ùzTestCase.cleanup)Ú__name__Ú
__module__Ú__qualname__r"   ZLARGE_TIMEOUTZ__timeout__r   r   r   r   r   r#   r   r'   r   r   r   r   r   #   s    r   c                   @   s2   e Zd Zdd„ Zdd„ Zdd„ Zde_dd	„ Zd
S )ÚPoolBasicTestsc                 C   s²   |   d¡}g }| |jd¡}| ¡  |  |dg¡ t d¡ | |jd¡ |  |dg¡ | |jd¡ |  |dg¡ | |jd¡ |  |dg¡ t d¡ |  t	|ƒg d¢¡ d S )	Né   é   r   )r,   )r    )é   ç{®Gáz„?)r-   r,   r    r.   )
r   ÚspawnÚappendÚgetÚassertEqualÚgeventr   Úapply_asyncÚassertEqualFlakyRaceConditionÚsorted)r   r   ÚrÚfirstr   r   r   Útest_execute_asyncI   s   


z!PoolBasicTests.test_execute_asyncc                 C   s*   |   d¡}| dd„ d¡}|  |d¡ d S )Nr-   c                 S   s   d| fS )NÚfoor   )Úar   r   r   Ú<lambda>^   s    z+PoolBasicTests.test_apply.<locals>.<lambda>)r-   )r;   r-   )r   Úapplyr3   )r   r   Úresultr   r   r   Ú
test_apply\   s   
zPoolBasicTests.test_applyc                 C   sL   |   d¡}dd„ }|  t¡ | |¡ W d   ƒ d S 1 sw   Y  d S )Nr-   c                   S   s   t ƒ ‚r
   r   r   r   r   r   Úraiserd   r   z0PoolBasicTests.test_apply_raises.<locals>.raiser)r   ÚassertRaisesr   r>   )r   r   rA   r   r   r   Útest_apply_raisesa   s
   
"ÿz PoolBasicTests.test_apply_raisesFc                 C   s@   d| _ |  t¡ |  d¡ W d   ƒ d S 1 sw   Y  d S )NFéÿÿÿÿ)Úswitch_expectedrB   Ú
ValueErrorr   r   r   r   r   Útest_init_valueerrorn   s   "ÿz#PoolBasicTests.test_init_valueerrorN)r(   r)   r*   r:   r@   rC   Úerror_fatalrG   r   r   r   r   r+   G   s    r+   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTimingWrapperc                 C   s   || _ d | _d S r
   )ÚfuncÚelapsed)r   Zthe_funcr   r   r   Ú__init__y   s   
zTimingWrapper.__init__c                 O   s4   t ƒ }z| j|i |¤ŽW t ƒ | | _S t ƒ | | _w r
   )r   rJ   rK   )r   ÚargsÚkwdsÚtr   r   r   Ú__call__}   s   zTimingWrapper.__call__N)r(   r)   r*   rL   rP   r   r   r   r   rI   w   s    rI   ç        c                 C   s   t |ƒ | |  S r
   )r   )ÚxÚwaitr   r   r   Úsqr…   s   rT   c                 C   s   t t ¡ d ƒ | |  S )Nçš™™™™™¹?)r   Úrandom©rR   r   r   r   Úsqr_random_sleepŠ   ó   rX   )gË¡E¶óý´?gìQ¸…ë¡?gìQ¸…ëÁ?c                   @   s*   e Zd ZdZdZdd„ Zejdd„ ƒZdS )Ú_AbstractPoolTestr-   Fc                 C   s   t j | ¡ |  | j¡ d S r
   )r"   r   ÚsetUpr   r   r   r   r   r   r[   —   s   z_AbstractPoolTest.setUpc                    sv   ˆ j j}ˆ jr‡ fdd„}ˆ  |ttdƒƒttttdƒƒƒ¡ ˆ  |ttdƒƒttttdƒƒƒ¡ ˆ j  ¡  ˆ ` ~d S )Nc                    s   t ˆ j | |¡ƒS r
   )Úlistr   Úmap)ÚfÚir   r   r   r=   Ÿ   ó    z,_AbstractPoolTest.test_map.<locals>.<lambda>é
   éd   )r   r]   Ú
MAP_IS_GENr3   rT   r$   r\   r   )r   Zpmapr   r   r   Útest_map›   s   $$
z_AbstractPoolTest.test_mapN)	r(   r)   r*   r   rc   r[   r"   Úignores_leakcheckrd   r   r   r   r   rZ   ‘   s    rZ   ra   iè  é2   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!S )"ÚTestPoolc                 C   s„   ddl m} ddlm} | j |¡}|  ||¡ t|ƒ}|  d|¡ |  d|¡ |  d|¡ ddl	m
} d |ƒ ¡}|  d	|¡ d S )
Nr   )Ú
getcurrent)Ú_WorkerGreenletZThreadPoolWorkerZthread_identzhub=)Úformat_run_infoÚ
z<ThreadPoolWorker)Zgreenletrh   Úgevent.threadpoolri   r   r>   ÚassertIsInstanceÚreprZassertInZgevent.utilrj   Újoin)r   rh   ri   Zworker_greenletr8   rj   Úinfor   r   r   Útest_greenlet_classµ   s   zTestPool.test_greenlet_classc                 C   s@   | j j}|  |tdƒtdƒ¡ |  |tdddiƒtdd¡ d S )N)é   rr   r   rR   r    rW   )r   r>   r3   rT   )r   Zpapplyr   r   r   r@   Å   s   "zTestPool.test_applyc                 C   s>   | j  tdtf¡}t|jƒ}|  |ƒ d¡ |  |jtd¡ d S )Né   é1   r-   )	r   r5   rT   ÚTIMEOUT1rI   r2   r3   ÚassertTimeoutAlmostEqualrK   ©r   Úresr2   r   r   r   Ú
test_asyncÊ   s   
zTestPool.test_asyncc                 C   s`   g }| j jtdtf|jd}t|jƒ}|  |ƒ d¡ |  |j	td¡ t
 d¡ |  |dg¡ d S )Nrs   )Úcallbackrt   r-   r   )r   r5   rT   ru   r1   rI   r2   r3   rv   rK   r4   r   )r   r?   rx   r2   r   r   r   Útest_async_callbackÐ   s   

zTestPool.test_async_callbackc                 C   sP   | j  tdtd f¡}t|jƒ}| jtj|td |  	|j
td¡ | j  ¡  d S )Né   çš™™™™™É?©Útimeoutr-   )r   r5   rT   ÚTIMEOUT2rI   r2   rB   r4   ÚTimeoutrv   rK   ro   rw   r   r   r   Útest_async_timeoutÙ   s
   
zTestPool.test_async_timeoutc                 C   s4   | j  tttƒ¡}|  t|ƒtttttƒƒƒ¡ d S r
   )r   ÚimaprT   r$   ÚSMALL_RANGEr3   r\   r]   ©r   Úitr   r   r   Útest_imap_list_smallà   ó   "zTestPool.test_imap_list_smallc                 C   óF   | j  tttƒ¡}ttƒD ]}|  t|ƒ|| ¡ q|  tt|¡ d S r
   )	r   rƒ   rT   r$   r„   r3   ÚnextrB   ÚStopIteration©r   r†   r_   r   r   r   Útest_imap_it_smallä   ó   zTestPool.test_imap_it_smallc                 C   r‰   r
   )	r   rƒ   rT   r$   ÚLARGE_RANGEr3   rŠ   rB   r‹   rŒ   r   r   r   Útest_imap_it_largeê   rŽ   zTestPool.test_imap_it_largec                 C   sN   | j  tttƒ¡}ttƒD ]}|  t|ƒ|| ¡ t ¡  q|  	t
t|¡ d S r
   )r   rƒ   rT   r$   r„   r3   rŠ   r   r%   rB   r‹   rŒ   r   r   r   Útest_imap_gcð   s
   
zTestPool.test_imap_gcc                 C   sŽ   | j  tttƒ¡}g }ttƒD ]}| t|ƒ¡ t ¡  q|  	t
¡ t|ƒ W d   ƒ n1 s1w   Y  |  t|ƒdd„ ttƒD ƒ¡ d S )Nc                 S   s   g | ]}|| ‘qS r   r   ©Ú.0rR   r   r   r   Ú
<listcomp>ÿ   s    z3TestPool.test_imap_unordered_gc.<locals>.<listcomp>)r   Úimap_unorderedrT   r$   r„   r1   rŠ   r   r%   rB   r‹   r3   r7   )r   r†   r?   r&   r   r   r   Útest_imap_unordered_gc÷   s   

ÿ"zTestPool.test_imap_unordered_gcc                 C   s4   | j  tttƒ¡}|  t|ƒtttttƒƒƒ¡ d S r
   )	r   rƒ   rX   r$   r„   r3   r\   r]   rT   r…   r   r   r   Útest_imap_random  rˆ   zTestPool.test_imap_randomc                 C   sd   | j  tttƒ¡}|  t|ƒtttttƒƒƒ¡ | j  tttƒ¡}|  t|ƒtttttƒƒƒ¡ d S r
   )	r   r•   rT   r$   r   r3   r7   r\   r]   r…   r   r   r   Útest_imap_unordered  s   "zTestPool.test_imap_unorderedc                 C   s4   | j  tttƒ¡}|  t|ƒttt	ttƒƒƒ¡ d S r
   )
r   r•   rX   r$   r„   r3   r7   r\   r]   rT   r…   r   r   r   Útest_imap_unordered_random  rˆ   z#TestPool.test_imap_unordered_randomc                 C   s–   | j pd}| j tdg|d  ¡}t d¡ z/| jd| j  d dd | j ¡  W d   ƒ n1 s3w   Y  W | ¡  d S W | ¡  d S | ¡  w )Nra   rU   r,   ç      à?r   )Zmin_time)r   r   Z	map_asyncr   r4   Zruns_in_given_timer   ro   )r   r   r?   r   r   r   Útest_terminate  s   

ÿýzTestPool.test_terminatec                 C   s   t t|ƒd ƒ t|ƒS )Ng      $@)r   ÚfloatÚstr)r   rR   r   r   r   r     rY   zTestPool.sleepc                 C   sF   t | j | jg d¢¡ƒ}| jjdkrg d¢}ng d¢}|  ||¡ d S )N)ra   r-   r,   r-   )Ú10Ú1Ú2)rŸ   r    rž   )r\   r   r•   r   r   r3   )r   r?   Úexpectedr   r   r   Útest_imap_unordered_sleep  s
   
z"TestPool.test_imap_unordered_sleepN)r(   r)   r*   rq   r@   ry   r{   r‚   r‡   r   r   r‘   r–   r—   r˜   r™   r›   r   r¢   r   r   r   r   rg   ³   s"    	

rg   c                   @   s   e Zd ZdZejdd„ ƒZdS )Ú	TestPool2r,   c                    s6   | j ‰‡ ‡fdd„}dd„ ‰ ˆ |¡}|  |d¡ d S )Nc                      s
   ˆ  ˆ ¡S r
   )r>   r   ©ÚbÚpr   r   r<   /  s   
z)TestPool2.test_recursive_apply.<locals>.ac                   S   s   t  ¡  t  d¡ dS )Nçü©ñÒMbP?ÚB©r4   r   r   r   r   r   r¥   2  s   
z)TestPool2.test_recursive_apply.<locals>.br¨   )r   r>   r3   )r   r<   r?   r   r¤   r   Útest_recursive_apply+  s
   
zTestPool2.test_recursive_applyN)r(   r)   r*   r   r"   re   rª   r   r   r   r   r£   (  s    r£   c                   @   ó   e Zd ZdZdS )Ú	TestPool3r    N©r(   r)   r*   r   r   r   r   r   r¬   >  ó    r¬   c                   @   r«   )Ú
TestPool10ra   Nr­   r   r   r   r   r¯   B  r®   r¯   c                   @   s2   e Zd ZdZe ejoejoejd¡dd„ ƒZ	dS )ÚTestJoinEmptyFzqThis sometimes appears to crash in PyPy2 5.9.0, but never crashes on macOS or local Ubunto with same PyPy versionc                 C   s   |   d¡}| ¡  d S ©Nr-   )r   ro   ©r   r   r   r   r   Útest[  s   
zTestJoinEmpty.testN)
r(   r)   r*   rE   r"   ZskipIfr	   ZLIBUVZRUNNING_ON_TRAVISr³   r   r   r   r   r°   X  s    ÿr°   c                   @   s,   e Zd ZdZejdd„ ƒZejdd„ ƒZdS )Ú	TestSpawnTc                    s¼   |   d¡}|  t|ƒd¡ g ‰ ‡ fdd„}| |dd¡ |  t|ƒd¡ | |dd¡ |  t|ƒd¡ t d	¡ |  ˆ dg¡ |  t|ƒd¡ t d	¡ |  ˆ ddg¡ |  t|ƒd¡ d S )
Nr-   r   c                    s   t |ƒˆ  | ¡gS r
   )r   r1   )ÚitemÚseconds©Úlogr   r   r=   m  r`   z'TestSpawn.test_basics.<locals>.<lambda>r<   rU   r¥   r,   g333333Ã?)r   r3   Úlenr0   r4   r   )r   r   Zsleep_n_logr   r·   r   Útest_basicsh  s   


zTestSpawn.test_basicsc                    sb   |   d¡}|   d¡‰ ‡ fdd„}| |¡}|  t¡ | ¡  W d   ƒ d S 1 s*w   Y  d S )Nr-   r,   c                      s   ˆ   dd„ ¡ d S )Nc                   S   ó   dS )NZHir   r   r   r   r   r=   „  ó    zMTestSpawn.test_cannot_spawn_from_other_thread.<locals>.func.<locals>.<lambda>)r0   r   ©Zpool2r   r   rJ   ƒ  s   z;TestSpawn.test_cannot_spawn_from_other_thread.<locals>.func)r   r0   rB   r   r2   )r   Zpool1rJ   rx   r   r½   r   Ú#test_cannot_spawn_from_other_thread{  s   



"ÿz-TestSpawn.test_cannot_spawn_from_other_threadN)r(   r)   r*   rE   r"   re   rº   r¾   r   r   r   r   r´   e  s    
r´   c                   c   s    dV  dV  t j‚)Nr-   r,   )r"   r   r   r   r   r   Ú
error_iterŠ  s   €r¿   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestErrorInIteratorFc                 C   s6   |   d¡| _|  tj| jjdd„ tƒ ¡ t d¡ d S )Nr    c                 S   ó   d S r
   r   rW   r   r   r   r=   –  r¼   z*TestErrorInIterator.test.<locals>.<lambda>r§   )	r   r   rB   r"   r   r]   r¿   r4   r   r   r   r   r   r³   ”  s   zTestErrorInIterator.testc                    s4   ˆ   d¡ˆ _‡ fdd„}ˆ  tj|¡ t d¡ d S )Nr    c                      s   t ˆ j dd„ tƒ ¡ƒS )Nc                 S   rÁ   r
   r   rW   r   r   r   r=     r¼   zGTestErrorInIterator.test_unordered.<locals>.unordered.<locals>.<lambda>)r\   r   r•   r¿   r   r   r   r   Ú	unorderedœ  s   z5TestErrorInIterator.test_unordered.<locals>.unorderedr§   )r   r   rB   r"   r   r4   r   )r   rÂ   r   r   r   Útest_unordered™  s   z"TestErrorInIterator.test_unorderedN)r(   r)   r*   rH   r³   rÃ   r   r   r   r   rÀ     s    rÀ   c                   @   s"   e Zd Zdd„ Zejdd„ ƒZdS )ÚTestMaxsizec                 C   sv   |   d¡| _g }t | jj|jd¡ t d| jj|jd¡ t d¡ |  |g ¡ d| j_t d¡ |  	|ddg¡ d S )Nr   r-   r/   r,   g{®Gáz”?)
r   r   r4   r0   r1   Zspawn_laterr   r3   r   r6   )r   Údoner   r   r   Útest_inc¥  s   

zTestMaxsize.test_incc                 C   sn   |   d¡ }| _| td¡ | td¡ | td¡ t d¡ |  |jd¡ d|_t d¡ |  |jd¡ d S )Nr    rU   r}   g333333Ó?r,   r   )	r   r   r0   r   r4   ÚassertGreaterEqualr   r   r6   r²   r   r   r   Útest_setzero³  s   

zTestMaxsize.test_setzeroN)r(   r)   r*   rÆ   r"   re   rÈ   r   r   r   r   rÄ   £  s    rÄ   c                   @   s   e Zd Ze ¡ dd„ ƒZdS )ÚTestSizec                 C   sê   | j ddd }| _|  |jd¡ d|_|  |jd¡ d|_|  |jd¡ d|_|  |jd¡ |  t¡ d|_W d   ƒ n1 sBw   Y  |  t¡ d|_W d   ƒ n1 sZw   Y  d|_|  |jd¡ d|_|  |jd¡ d S )Nr,   F©r   r   r-   rD   r    )r   r   r3   r   rB   rF   r²   r   r   r   r³   Â  s$   ÿÿzTestSize.testN)r(   r)   r*   r"   Zreraises_flaky_race_conditionr³   r   r   r   r   rÉ   À  s    rÉ   c                   @   ó   e Zd Zdd„ ZdS )ÚTestRefc                 C   sÐ   |   d¡ }| _g }tƒ }||_|j}~tƒ G | |tƒ fdtƒ i¡}|  |t¡ t	 
d¡ | t |¡¡ ~~trCt ¡  t ¡  |D ]}|  |ƒ ¡ qE|  dt|ƒ¡ W d   ƒ d S 1 saw   Y  d S )Nr,   Úkwarg1rU   r.   )r   r   Ú	SomeClassÚrefsrJ   r   r>   ÚObjectrm   r4   r   r1   ÚweakrefÚrefr	   r   r%   ÚassertIsNoner3   r¹   )r   r   rÏ   ÚobjrJ   r?   r8   r   r   r   r³   Û  s&   
"ðzTestRef.testN©r(   r)   r*   r³   r   r   r   r   rÌ   Ù  ó    rÌ   c                   @   ó   e Zd ZdS )rÐ   N©r(   r)   r*   r   r   r   r   rÐ   ÷  ó    rÐ   c                   @   s   e Zd ZdZddd„ZdS )rÎ   Nc                 C   s&   t ƒ }| j dd„ |||fD ƒ¡ |S )Nc                 S   s   g | ]}t  |¡‘qS r   )rÑ   rÒ   r’   r   r   r   r”     s    z"SomeClass.func.<locals>.<listcomp>)rÐ   rÏ   Úextend)r   Zarg1rÍ   r?   r   r   r   rJ   ÿ  s   zSomeClass.funcr
   )r(   r)   r*   rÏ   rJ   r   r   r   r   rÎ   û  s    rÎ   c                   C   rÁ   r
   r   r   r   r   r   Únoop  ó   rÛ   c                   @   rË   )ÚTestRefCountc                 C   s*   |   d¡}| t¡ t d¡ | ¡  d S )Nr-   r   )r   r0   rÛ   r4   r   r   r²   r   r   r   r³     s   


zTestRefCount.testNrÕ   r   r   r   r   rÝ   	  rÖ   rÝ   )ÚmonkeyÚThreadPoolExecutorzRequires ThreadPoolExecutorc                   @   sr   e Zd ZdZdZedd„ ƒZdZedd„ ƒZedd	„ ƒZ	ed
d„ ƒZ
ejdd„ ƒZejdd„ ƒZejdd„ ƒZdS )ÚTestTPEr-   Tc                 C   s   t jjS r
   )r4   Ú
threadpoolrß   r   r   r   r   r     s   zTestTPE.ClassUnderTestFc                 C   ó   ddl m} |S )Nr   )ÚTimeoutError)Úconcurrent.futuresrã   )r   ÚFutureTimeoutErrorr   r   r   rå   #  ó   zTestTPE.FutureTimeoutErrorc                 C   râ   )Nr   )rS   )rä   rS   )r   Úcf_waitr   r   r   rç   (  ræ   zTestTPE.cf_waitc                 C   râ   )Nr   )Úas_completed)rä   rè   )r   Úcf_as_completedr   r   r   ré   -  ræ   zTestTPE.cf_as_completedc           	         s`  |   t d¡| j¡ | j}g ‰ dd„ }dd„ }| |¡}d|_| |¡ | j| j	|j
dd d	d
„ }t |¡}|   | 
¡ d¡ |  | ¡ ¡ |  | ¡ ¡ t ¡  |   |jd¡ |  | ¡ ¡ |   |jd¡ | ‡ fdd„¡ |   ˆ dg¡ |  |f¡\}}|   t|ƒ|g¡ |   t|  |f¡ƒ|g¡ |   |jd¡ t ¡  |   |jd¡ | ¡  ~~| `d S )NÚ	threadingc                   S   ó   t  d¡ dS ©Nrš   é*   r©   r   r   r   r   Úfn:  ó   
zTestTPE.test_future.<locals>.fnc                 S   s   |  j d7  _ t d¡‚)Nr-   zExpected, ignored)Ú
calledbackr"   r   )Úfuturer   r   r   rz   >  s   
z%TestTPE.test_future.<locals>.callbackr   r§   r~   c                   S   r»   ©Néà  r   r   r   r   r   ÚspawnedG  rÜ   z$TestTPE.test_future.<locals>.spawnedrí   r-   ró   c                    s
   ˆ   d¡S )NT©r1   )r^   ©rð   r   r   r=   [  s   
 z%TestTPE.test_future.<locals>.<lambda>T)r3   rÞ   Úis_module_patchedÚMONKEY_PATCHEDr   Úsubmitrð   Úadd_done_callbackrB   rå   r?   r4   r0   Ú
assertTruerÅ   ZassertFalseÚ	cancelledr   ÚreadyÚvaluerç   r\   ré   r   )	r   r   rî   rz   rñ   rô   Úspawned_greenletrÅ   Ú	_not_doner   rö   r   Útest_future2  s@   ÿ


zTestTPE.test_futurec           
      C   sÐ   |   t d¡| j¡ | j}dd„ }| |¡}| jrU| j|fdd\}}|   t|ƒ|g¡ dd„ }t 	|¡}|  |f¡\}}	|   t|ƒ|g¡ |  
| ¡ ¡ |   |jd¡ n	|  t| j|f¡ | ¡  ~~| `d S )	Nrê   c                   S   rë   rì   r©   r   r   r   r   rî   v  rï   z4TestTPE.test_future_wait_module_function.<locals>.fnr§   r~   c                   S   r»   rò   r   r   r   r   r   rô   €  rÜ   z9TestTPE.test_future_wait_module_function.<locals>.spawnedró   )r3   rÞ   r÷   rø   r   rù   rç   r\   r4   r0   rû   rý   rþ   rB   ÚAttributeErrorr   )
r   r   rî   rñ   Ú_doneÚnot_donerô   rÿ   rÅ   r   r   r   r   Ú test_future_wait_module_functionn  s(   ÿ

z(TestTPE.test_future_wait_module_functionc                 C   sŒ   |   t d¡| j¡ | j}dd„ }| |¡}dd„ }t |¡}t |f¡}|   t	|ƒ|g¡ |  
| ¡ ¡ |   |jd¡ | ¡  ~~| `d S )Nrê   c                   S   rë   rì   r©   r   r   r   r   rî   ™  rï   z4TestTPE.test_future_wait_gevent_function.<locals>.fnc                   S   r»   rò   r   r   r   r   r   rô   Ÿ  rÜ   z9TestTPE.test_future_wait_gevent_function.<locals>.spawnedró   )r3   rÞ   r÷   rø   r   rù   r4   r0   rS   r\   rû   rý   rþ   r   )r   r   rî   rñ   rô   rÿ   rÅ   r   r   r   Ú test_future_wait_gevent_function’  s    ÿ

z(TestTPE.test_future_wait_gevent_functionN)r(   r)   r*   r   rc   Úpropertyr   rø   rå   rç   ré   r"   re   r  r  r  r   r   r   r   rà     s$    




;
#rà   c                   @   rË   )ÚTestThreadResultc                    sÀ   g ‰G dd„ dt ƒ‰ ‡ ‡fdd„}tj d t ¡ |¡‰‡‡fdd„}t |¡ ¡  |  ˆ ¡ tdƒD ]}t 	d¡ q3W d   ƒ n1 sEw   Y  |  
ˆd	d	g¡ |  ˆj¡ |  ˆj¡ d S )
Nc                   @   r×   )zMTestThreadResult.test_exception_in_on_async_doesnt_crash.<locals>.MyExceptionNrØ   r   r   r   r   ÚMyExceptionµ  rÙ   r	  c                      s   ˆ  d¡ ˆ ‚r±   rõ   r   )r	  Úcalledr   r   Úbad_when_ready¸  rï   zPTestThreadResult.test_exception_in_on_async_doesnt_crash.<locals>.bad_when_readyc                      s   ˆ   d¡ ˆ d¡ d S )Nr-   rí   )r1   Úsetr   )r
  Útrr   r   Úwake¾  s   
zFTestThreadResult.test_exception_in_on_async_doesnt_crash.<locals>.wakerr   r§   r-   )Ú	Exceptionr4   rá   ZThreadResultZget_hubr0   r2   rB   r$   r   r3   rÓ   rþ   ÚassertIsNotNoneZreceiver)r   r  r  r&   r   )r	  r
  r  r   Ú'test_exception_in_on_async_doesnt_crash±  s   ÿÿz8TestThreadResult.test_exception_in_on_async_doesnt_crashN)r(   r)   r*   r  r   r   r   r   r  ¯  rÖ   r  c                       sX   e Zd ZdZdZ‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Z‡  ZS )ÚTestWorkerProfileAndTraceNc                    s*   t t| ƒ ¡  tj ¡ | _tj ¡ | _d S r
   )	Úsuperr  r[   r4   rá   Ú_get_thread_profileÚold_profileÚ_get_thread_traceÚ	old_tracer   ©Ú	__class__r   r   r[   Ü  s   zTestWorkerProfileAndTrace.setUpc                    s2   dd l }| | j¡ | | j¡ tt| ƒ ¡  d S ©Nr   )rê   Ú
setprofiler  Úsettracer  r  r  ÚtearDown©r   rê   r  r   r   r  á  s   z"TestWorkerProfileAndTrace.tearDownc                 C   ó(   dd l }| | ¡ |  tj ¡ | ¡ d S r  )rê   r  ÚassertIsr4   rá   r  r  r   r   r   Útest_get_profileç  ó   
z*TestWorkerProfileAndTrace.test_get_profilec                 C   r  r  )rê   r  r   r4   rá   r  r  r   r   r   Útest_get_traceì  r"  z(TestWorkerProfileAndTrace.test_get_tracec           
         sð   dd l }dd l}t|d| ƒ}t|d| ƒ‰dg‰‡fdd„}‡‡fdd„}g ‰g ‰ | ‰G ‡ ‡‡fdd	„d	tƒ}|| _| jd
dd}t||ƒsIJ ‚||ƒ | |¡}	|  |	d¡ |  	ˆd d
¡ | 
¡  |  ˆ|d |g¡ |  ˆ ||d g¡ d S )Nr   r  r2   c                     s   ˆ d  d7  < d S )Nr   r-   r   )Ú_args)r
  r   r   rz   ù  s   zETestWorkerProfileAndTrace._test_func_called_in_task.<locals>.callbackc                      s   ˆ  ˆ ¡ dS )Né¥  )r  r   )Úgetterr³   r   r   Útaskü  rï   zATestWorkerProfileAndTrace._test_func_called_in_task.<locals>.taskc                       s&   e Zd ZG ‡ ‡‡fdd„dejƒZdS )zATestWorkerProfileAndTrace._test_func_called_in_task.<locals>.Poolc                       s(   e Zd Z‡‡fdd„Z‡ ‡fdd„ZdS )zQTestWorkerProfileAndTrace._test_func_called_in_task.<locals>.Pool._WorkerGreenletc                    ó<   ˆ   |¡ ˆ   ˆƒ ¡ tjj| |g|¢R Ž  ˆ   ˆƒ ¡ d S r
   )r1   r   ri   Ú_before_run_task©r   rJ   rM   )Úbefore_taskr&  r   r   r)    ó   
zbTestWorkerProfileAndTrace._test_func_called_in_task.<locals>.Pool._WorkerGreenlet._before_run_taskc                    r(  r
   )r1   r   ri   Ú_after_run_taskr*  )Ú
after_taskr&  r   r   r-    r,  zaTestWorkerProfileAndTrace._test_func_called_in_task.<locals>.Pool._WorkerGreenlet._after_run_taskN)r(   r)   r*   r)  r-  r   ©r.  r+  r&  r   r   ri     s    ri   N)r(   r)   r*   r   ri   r   r/  r   r   ÚPool  s    r0  r-   TrÊ   r%  )rê   Úsysr!   r   r   r   Ú
isinstancer>   r3   rÇ   r   )
r   rJ   rê   r1  Úsetterrz   r'  r0  r   rx   r   )r.  r+  r
  r&  r³   r   Ú_test_func_called_in_taskñ  s*   

z3TestWorkerProfileAndTrace._test_func_called_in_taskc                 C   ó   |   d¡ d S )NZprofile©r4  r   r   r   r   Útest_profile_called_in_task0  ó   z5TestWorkerProfileAndTrace.test_profile_called_in_taskc                 C   r5  )NÚtracer6  r   r   r   r   Útest_trace_called_in_task3  r8  z3TestWorkerProfileAndTrace.test_trace_called_in_task)r(   r)   r*   r  r  r[   r  r!  r#  r4  r7  r:  Ú__classcell__r   r   r  r   r  Ô  s    ?r  Ú__main__)rQ   )<Ú
__future__r   r   r   Ú
contextlibrV   rÑ   r   rl   r4   r   Zgevent.exceptionsr   Zgevent.testingÚtestingr"   r   r	   Úcontextmanagerr   r   r+   ÚobjectrI   rT   rX   ru   r€   ZTIMEOUT3rZ   r„   r   ZWINZRUN_COVERAGEr#   rg   r£   re   r¬   r¯   r°   r´   r¿   rÀ   rÄ   rÉ   rÌ   rÐ   rÎ   rÛ   rÝ   rÞ   Z
skipUnlessÚhasattrrá   rà   r  r  r(   Úmainr   r   r   r   Ú<module>   sn    

$0

u%


þ %
dÿ