
    i                         d Z ddlmZ ddlmZ ddlm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  G d	 d
e
j                  Zedk    r e
j                     dS dS )z
Tests for running ``gevent.monkey`` as a module to launch a
patched script.

Uses files in the ``monkey_package/`` directory.
    )print_function)absolute_import)divisionN)testing)absolute_pythonpath)runc                   V    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zd ZdS )TestRunNc                     t                      | _        t          j                    | _        t          j        t          j                            t                               d S N)	r   abs_pythonpathosgetcwdcwdchdirpathdirname__file__selfs    O/usr/local/lib/python3.11/dist-packages/gevent/tests/test__monkey_module_run.pysetUpzTestRun.setUp   sA    1339;;
**+++++    c                 8    t          j        | j                   d S r   )r   r   r   r   s    r   tearDownzTestRun.tearDown   s    
r   Fc                 D   t           j                                        }d|d<   | j        r
| j        |d<   t	          ddd|d          }t
          j        ddg}|r|                    d	           ||d
gz  }t          |fi |}| 	                    |           |rt
          j        d|dg}nt
          j        |dg}t          |fi |}| 	                    |           |j
        }|j
        }	|                     ||	           |                     |j        |j                   |S )NignorePYTHONWARNINGS
PYTHONPATHT
   )buffer_outputquietnestedenvtimeoutz-mzgevent.monkeyz--modulepatchedstdlib)r   environcopyr   dictsys
executableappendr   
assertTrueoutput_linesassertEqualerror)
r   scriptmoduler$   
run_kwargsargsmonkey_result
std_resultmonkey_out_linesstd_out_liness
             r   _runzTestRun._run   sj   joo ( 	4 $ 3C
 
 

 o6 	$KK
#####
 

 
 	&&& 	6ND&(;DDNFH5D
 

 

 	
###(5"/)=999,j.>???r   c                 l    |                      t          j                            dd                     d S )Nmonkey_packagez	script.py)r:   r   r   joinr   s    r   test_run_simplezTestRun.test_run_simpleG   s+    		"',,/==>>>>>r   c                     |                      d|          }|                     |d                             d          |d                    |                     |d                                         d           d S )Nr<   r3   r   z__main__.py   __main__)r:   r.   endswithr0   strip)r   r3   liness      r   _run_packagezTestRun._run_packageJ   sl    		*6	::a)).9958DDDq));77777r   c                 2    |                      d           d S )NFr@   rF   r   s    r   test_run_packagezTestRun.test_run_packageP   s    '''''r   c                 2    |                      d           d S )NTr@   rH   r   s    r   test_run_modulezTestRun.test_run_moduleT   s    &&&&&r   c                    |                      t          j                            dd                    }|                     |d                                         d           |d                             dd          |d<   |                     |d                                                             d                     |                     |d	                                         d|           d S )
Nr<   zissue302monkey.pyr   TruerA   \/z monkey_package/issue302monkey.py   )	r:   r   r   r=   r0   rD   replacer.   rC   )r   monkey_liness     r   test_issue_302zTestRun.test_issue_302X   s    yy.>@S!T!TUUa..00':::&q/11%>>QQ--//889\]]^^^a..00'<HHHHHr   c                     |                      t          j                            dd                    }|                     |ddg           d S )Nr<   zthreadpool_monkey_patches.pyFalse2)r:   r   r   r=   r0   r   outs     r   &test_threadpool_in_patched_after_patchz.TestRun.test_threadpool_in_patched_after_patchl   sG     ii%57UVVWWwn-----r   c                 d    |                      dd          }|                     |ddg           d S )Nz(monkey_package.threadpool_monkey_patchesTr@   rU   rV   r:   r0   rW   s     r   -test_threadpool_in_patched_after_patch_modulez5TestRun.test_threadpool_in_patched_after_patch_moduler   s:     iiB4iPPwn-----r   c                 d    |                      dd          }|                     |g d           d S )Nz#monkey_package.threadpool_no_monkeyTr@   )rU   rU   rV   r[   rW   s     r   .test_threadpool_not_patched_after_patch_modulez6TestRun.test_threadpool_not_patched_after_patch_modulex   s=     ii=diKK55566666r   )F)__name__
__module____qualname__maxDiffr   r   r:   r>   rF   rI   rK   rS   rY   r\   r^    r   r   r
   r
      s        G, , ,
  &  &  &  & P? ? ?8 8 8( ( (' ' 'I I I(. . .. . .7 7 7 7 7r   r
   rB   )__doc__
__future__r   r   r   r   os.pathr+   geventr   	greentestgevent.testing.utilr   r   TestCaser
   r_   mainrc   r   r   <module>rl      s     & % % % % % & & & & & &       
			  



 ' ' ' ' ' ' 3 3 3 3 3 3 # # # # # #h7 h7 h7 h7 h7i  h7 h7 h7T zIN r   