B
    on¦d  ã               @   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)Úshowwarning_orig© ú2/tmp/pip-unpacked-wheel-ckfyei3v/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k	rft ||¡}| ¡  t d| |¡}| ¡  ˆ ¡ \}}	| ¡ |	 ¡  }}	ˆjdkr¦d	 	ˆj||	¡}
t
|
ƒ‚|dk	rÊt ||¡sÊt
d
 	||¡ƒ‚|dk	rît ||	¡sît
d 	||	¡ƒ‚W d|dk	r| ¡  | ¡  X 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.
        zTimeout running N)r   ÚwarnÚ	terminater   )ÚcmdÚprocr   r   Úterminate_process4   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.
        zTimeout running N)r   r   Úkillr   )r   r   r   r   Úkill_process=   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   r   Úcheck_subprocess_call'   s:    


		


r-   )r   NN)Ú__doc__r   r   Úos.pathr   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(    