
    h                         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"                          yy)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                   T    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y)TestRunNc                     t               | _        t        j                         | _        t        j
                  t        j                  j                  t                     y N)	r   abs_pythonpathosgetcwdcwdchdirpathdirname__file__selfs    ^/var/www/html/engine/venv/lib/python3.12/site-packages/gevent/tests/test__monkey_module_run.pysetUpzTestRun.setUp   s3    1399;
*+    c                 B    t        j                  | j                         y r   )r   r   r   r   s    r   tearDownzTestRun.tearDown   s    
r   c                 d   t         j                  j                         }d|d<   | j                  r| j                  |d<   t	        ddd|d      }t
        j                  ddg}|r|j                  d	       ||d
gz  }t        |fi |}| j                  |       |rt
        j                  d|dg}nt
        j                  |dg}t        |fi |}| j                  |       |j                  }|j                  }	| 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   s4   jjoo ( $ 3 3C

 o6KK
###

 	&NND&(;DNNFH5D


 	
#(55"//)=9,,j.>.>?r   c                 b    | j                  t        j                  j                  dd             y )Nmonkey_packagez	script.py)r:   r   r   joinr   s    r   test_run_simplezTestRun.test_run_simpleG   s    		"'',,/=>r   c                     | j                  d|      }| j                  |d   j                  d      |d          | j                  |d   j	                         d       y )Nr<   r3   r   z__main__.py   __main__)r:   r.   endswithr0   strip)r   r3   liness      r   _run_packagezTestRun._run_packageJ   sQ    		*6	:a)).958Dq);7r   c                 (    | j                  d       y )NFr@   rF   r   s    r   test_run_packagezTestRun.test_run_packageP   s    'r   c                 (    | j                  d       y )NTr@   rH   r   s    r   test_run_modulezTestRun.test_run_moduleT   s    &r   c                    | j                  t        j                  j                  dd            }| j	                  |d   j                         d       |d   j                  dd      |d<   | j                  |d   j                         j                  d             | j	                  |d	   j                         d|       y )
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Ua..0':&q/11%>QQ--/889\]^a..0'<Hr   c                     | j                  t        j                  j                  dd            }| j	                  |ddg       y )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   s7     ii%57UVWwn-r   c                 R    | j                  dd      }| j                  |ddg       y )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wn-r   c                 R    | j                  dd      }| j                  |g d       y )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56r   )F)__name__
__module____qualname__maxDiffr   r   r:   r>   rF   rI   rK   rS   rY   r\   r^    r   r   r
   r
      s@    G,
& P?8('I(..7r   r
   rB   )__doc__
__future__r   r   r   r   os.pathr+   geventr   	greentestgevent.testing.utilr   r   TestCaser
   r_   mainrc   r   r   <module>rl      sY    & &  
  
 ' 3 #h7i   h7T zINN r   