B
    \X                 @   s   d Z ddlZejjZddlZyddlmZ W n  ek
rL   ddl	mZ Y nX ddl
Z
ddlmZ e
jjejdddZG dd	 d	eZdddZdS )z(Testing utils for jupyter_client tests

    N)patch)TemporaryDirectorywinZWindows)reasonc               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )test_envzySet Jupyter path variables to a temporary directory
    
    Useful as a context manager or with explicit start/stop
    c          	   C   sT   t   | _}ttjt|jdt|jdt|jdt|jdd| _| j	  d S )NZjupyterZjupyter_dataZjupyter_runtimeZipython)ZJUPYTER_CONFIG_DIRZJUPYTER_DATA_DIRZJUPYTER_RUNTIME_DIRZ
IPYTHONDIR)
r   test_dirr   dictosenvironpjoinname	env_patchstart)selfZtd r   9lib/python3.7/site-packages/jupyter_client/tests/utils.pyr      s    


ztest_env.startc             C   s   | j   | j  d S )N)r   stopr   Zcleanup)r   r   r   r   r   #   s    
ztest_env.stopc             C   s   |    | jjS )N)r   r   r   )r   r   r   r   	__enter__'   s    ztest_env.__enter__c             G   s   |    d S )N)r   )r   exc_infor   r   r   __exit__+   s    ztest_env.__exit__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s
   
r    c             K   s   ddl m} |dkrt}|jf d| i|}|jtd}||d| |jtd}||d| |d d	 d
kspt|ds|jtd}||d| |d d | kst||d fS )zBwrapper for doing common steps for validating an execution request   )validate_messageNcode)ZtimeoutZexecute_replyZstatusZcontentZexecution_statebusyZsilentexecute_input)	Ztest_message_specr   ZKCexecuteZget_shell_msgZTIMEOUTZget_iopub_msgAssertionErrorget)r   Zkckwargsr   Zmsg_idZreplyr   r   r   r   r   r    .   s    
r    )r   N)r   r	   pathjoinr   sysZunittest.mockr   ImportErrorZmockZpytestZipython_genutils.tempdirr   ZmarkZskipifplatform
startswithZ
skip_win32objectr   r    r   r   r   r   <module>   s   