B
    t‹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© ú[/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/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„}z¨|dk	r@t ||¡}| ¡  ˆ ¡ \}}| ¡ | ¡  }}ˆ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 )	z§Runs a command in a subprocess with timeout in seconds.

    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 )NzTimeout running {})r   ÚwarnÚformatÚkillr   )ÚcmdÚprocr   r   Úkill_process1   s    z+check_subprocess_call.<locals>.kill_processNr   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Ú
returncoder   Ú
ValueErrorÚreÚsearchÚcancel)	r   ÚtimeoutZstdout_regexZstderr_regexr   Útimerr   r   Úmessager   )r   r   r   Úcheck_subprocess_call'   s2    



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(    