B
    ¦	ˆ\®  ã               @   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	ddl
m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dd„ Zd	dd„ZdS )
z
Helper for testing.
é    N)ÚPY3_OR_LATERc                 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ÚfnameZlnoÚfileÚline)Úshowwarning_orig© ú?lib/python3.7/site-packages/sklearn/externals/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„}t ||¡}z˜| ¡  ˆ ¡ \}}trZ| ¡ | ¡  }}ˆj	dkr|d 
ˆj	||¡}t|ƒ‚|dk	r t ||¡s td 
||¡ƒ‚|dk	rÄt ||¡sÄtd 
||¡ƒ‚W d| ¡  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_processr   z/Non-zero return code: {}.
Stdout:
{}
Stderr:
{}Nz,Unexpected stdout: {!r} does not match:
{!r}z,Unexpected stderr: {!r} does not match:
{!r})Ú
subprocessÚPopenÚPIPEÚ	threadingZTimerÚstartZcommunicater   ÚdecodeÚ
returncoder   Ú
ValueErrorÚreÚsearchZcancel)	r   ÚtimeoutZstdout_regexZstderr_regexr   Ztimerr   r   Úmessager   )r   r   r   Úcheck_subprocess_call'   s0    



r'   )r   NN)Ú__doc__r   r   Úos.pathr   r#   r   r   ZpytestZ_pytestZ sklearn.externals.joblib._compatr   ZraisesZwarnsZrunnerZSkippedZSkipTestZmarkZskipifZfixtureZparametrizer%   r   r'   r   r   r   r   Ú<module>   s&    