B
    U[                 @   s   d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ edd	d
ddddddd	ZG dd deZdd Zdd ZdS )z%Tests for kernel connection utilities    N)Config)TemporaryDirectoryTemporaryWorkingDirectory)str_to_bytes)connect)IPKernelAppz1.2.3.4Zipc               s   abc123zhmac-md5)	ZipZ	transportZ
shell_portZhb_portZ
iopub_portZ
stdin_portZcontrol_portkeyZsignature_schemec               @   s   e Zd Zg fddZdS )DummyKernelAppc             C   s   |    |   d S )N)Zinit_profile_dirZinit_connection_file)selfargv r   ;lib/python3.7/site-packages/ipykernel/tests/test_connect.py
initialize   s    zDummyKernelApp.initializeN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c           
   C   s   t  } t }|| j_d}t| |d}|  tj|j	|}||j
ksLtt|d}|d W d Q R X tj|s|tt||kst||_t||kstW d Q R X d S )Nzkernel.json)Zconfigconnection_filewz{})r   r   Z
ProfileDirlocationr   r   ospathjoinZconnection_dirZabs_connection_fileAssertionErroropenwriteexistsr   Zget_connection_filer   )ZcfgdcfZappZ
profile_cffr   r   r   test_get_connection_file   s    r$   c           	   C   s   t  :} tj| d}tj|ft t|}tj|dd}W d Q R X t|t	sTt
dd | D }|tksrt
t|}t|d |d< dd | D }|tkst
d S )Nzkernel.jsonT)Zunpackc             S   s   i | ]\}}|t kr||qS r   )sample_info).0kvr   r   r   
<dictcomp>7   s    z,test_get_connection_info.<locals>.<dictcomp>r   c             S   s   i | ]\}}|t kr||qS r   )r%   )r&   r'   r(   r   r   r   r)   <   s    )r   r   r   r   r   Zwrite_connection_filer%   Zget_connection_info
isinstancestrr   itemsjsonloadsr   )r!   r"   Z	json_infoinfoZsub_infoZinfo2Z	sub_info2r   r   r   test_get_connection_info/   s    

r0   )__doc__r-   r   Ztraitlets.configr   Zipython_genutils.tempdirr   r   Zipython_genutils.py3compatr   Z	ipykernelr   Zipykernel.kernelappr   dictr%   r   r$   r0   r   r   r   r   <module>   s   

