a
    Žù»jÕ  ã                   @   sš   d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	e	j
Z
e	jZejjZe	jjZe	jZe	jjZe	jjZe	jjZe	jZdd„ Zddd„ZdS )	z
Helper for testing.
é    Nc                     s   t j‰ d‡ fdd„	} | t _dS )z Redirect all warnings to stdout.Nr   c                    s   ˆ | |t j |¡|tjƒ d S )N)ÚosÚpathÚbasenameÚsysÚstdout)ÚmsgÚcatÚfnameÚlnoÚfileÚline©Zshowwarning_orig© ú4E:\soccer\ml_env\Lib\site-packages\joblib/testing.pyÚshowwarning   s    z'warnings_to_stdout.<locals>.showwarning)Nr   )Úwarningsr   )r   r   r   r   Úwarnings_to_stdout   s    r   é   c                    s,  t jˆ t jt jd�‰‡ ‡fdd„}‡ ‡fdd„}zÚ|durft ||¡}| ¡  t d| |¡}| ¡  ˆ ¡ \}}	| ¡ |	 ¡  }}	ˆjdkr¦d	 	ˆj||	¡}
t
|
ƒ‚|durÊt ||¡sÊt
d
 	||¡ƒ‚|durît ||	¡sît
d 	||	¡ƒ‚W |du�r(| ¡  | ¡  n|du�r&| ¡  | ¡  0 dS )a  Runs a command in a subprocess with timeout in seconds.

    A SIGTERM is sent after `timeout` and if it does not terminate, a
    SIGKILL is sent after `2 * timeout`.

    Also checks returncode is zero, stdout if stdout_regex is set, and
    stderr if stderr_regex is set.
    )r   Ústderrc                      s   t  dˆ › �¡ ˆ ¡  dS )zË
        Attempt to terminate a leftover process spawned during test execution:
        ideally this should not be needed but can help avoid clogging the CI
        workers in case of deadlocks.
        úTimeout running N)r   ÚwarnÚ	terminater   ©ÚcmdÚprocr   r   Úterminate_process0   s    z0check_subprocess_call.<locals>.terminate_processc                      s   t  dˆ › �¡ ˆ ¡  dS )z»
        Kill a leftover process spawned during test execution: ideally this
        should not be needed but can help avoid clogging the CI workers in
        case of deadlocks.
        r   N)r   r   Úkillr   r   r   r   Úkill_process9   s    z+check_subprocess_call.<locals>.kill_processNé   r   z/Non-zero return code: {}.
Stdout:
{}
Stderr:
{}z,Unexpected stdout: {!r} does not match:
{!r}z,Unexpected stderr: {!r} does not match:
{!r})Ú
subprocessÚPopenÚPIPEÚ	threadingÚTimerÚstartÚcommunicateÚdecodeÚ
returncodeÚformatÚ
ValueErrorÚreÚsearchÚcancel)r   ÚtimeoutZstdout_regexZstderr_regexr   r   Zterminate_timerZ
kill_timerr   r   Úmessager   r   r   Úcheck_subprocess_call%   sD    			
ÿÿÿÿÿ

þ
r/   )r   NN)Ú__doc__Úos.pathr   r*   r   r   r"   r   Z_pytestZpytestZraisesZwarnsÚrunnerZSkippedZSkipTestÚmarkZskipifZfixtureZparametrizer-   ZxfailÚparamr   r/   r   r   r   r   Ú<module>   s&   