U
    Nvf                     @   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 2/tmp/pip-unpacked-wheel-dylwa62s/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rd	
j	||	}
t|
|dk	rt||std

|||dk	rt||	std
||	W 5 |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.
        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.
        r   N)r   r   killr   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cancel	threadingTimerstartcommunicatedecode
returncodeformat
ValueErrorresearch)r   timeoutZstdout_regexZstderr_regexr   r   Zterminate_timerZ
kill_timerr   r   messager   r   r   check_subprocess_call'   sT    

		
  
 
 
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*     