o
    tPf                     @   s   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
 d
e
jZedkrEe
  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                   @   sj   e Zd ZdZdd Zdd Zd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 )TestRunNc                 C   s(   t  | _t | _ttjt d S N)	r   abs_pythonpathosgetcwdcwdchdirpathdirname__file__self r   e/var/www/html/humari/django-venv/lib/python3.10/site-packages/gevent/tests/test__monkey_module_run.pysetUp   s   
zTestRun.setUpc                 C   s   t | j d S r	   )r   r   r   r   r   r   r   tearDown   s   zTestRun.tearDownFc           
      C   s   t j }d|d< | jr| j|d< tddd|dd}tjddg}|r'|d	 ||d
g7 }t|fi |}| 	| |rDt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_linesr   r   r   _run   sF   




zTestRun._runc                 C   s   |  tjdd d S )Nmonkey_packagez	script.py)r5   r   r   joinr   r   r   r   test_run_simpleG   s   zTestRun.test_run_simplec                 C   s@   | j d|d}| |d d|d  | |d  d d S )Nr6   r.   r   z__main__.py   __main__)r5   r)   endswithr+   strip)r   r.   linesr   r   r   _run_packageJ   s   zTestRun._run_packagec                 C      | j dd d S )NFr9   r?   r   r   r   r   test_run_packageP      zTestRun.test_run_packagec                 C   r@   )NTr9   rA   r   r   r   r   test_run_moduleT   rC   zTestRun.test_run_modulec                 C   sn   |  tjdd}| |d  d |d dd|d< | |d  d | |d	  d| d S )
Nr6   zissue302monkey.pyr   Truer:   \/z monkey_package/issue302monkey.py   )	r5   r   r   r7   r+   r=   replacer)   r<   )r   monkey_linesr   r   r   test_issue_302X   s
   zTestRun.test_issue_302c                 C   s(   |  tjdd}| |ddg d S )Nr6   zthreadpool_monkey_patches.pyFalse2)r5   r   r   r7   r+   r   outr   r   r   &test_threadpool_in_patched_after_patchl   s   z.TestRun.test_threadpool_in_patched_after_patchc                 C   s"   | j ddd}| |ddg d S )Nz(monkey_package.threadpool_monkey_patchesTr9   rL   rM   r5   r+   rN   r   r   r   -test_threadpool_in_patched_after_patch_moduler      z5TestRun.test_threadpool_in_patched_after_patch_modulec                 C   s"   | j ddd}| |g d d S )Nz#monkey_package.threadpool_no_monkeyTr9   )rL   rL   rM   rQ   rN   r   r   r   .test_threadpool_not_patched_after_patch_modulex   rS   z6TestRun.test_threadpool_not_patched_after_patch_module)F)__name__
__module____qualname__maxDiffr   r   r5   r8   r?   rB   rD   rK   rP   rR   rT   r   r   r   r   r      s    
(r   r;   )__doc__
__future__r   r   r   r   os.pathr&   geventr   	greentestgevent.testing.utilr   r   TestCaser   rU   mainr   r   r   r   <module>   s    j