a
    ì<+b  ã                   @   s:   d dl Z d dlmZ G dd„ de jƒZedkr6e  ¡  dS )é    N)ÚInProcessKernelManagerc                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚInProcessKernelManagerTestCasec                 C   s   t ƒ | _d S ©N)r   Úkm©Úself© r   úKlib/python3.9/site-packages/ipykernel/inprocess/tests/test_kernelmanager.pyÚsetUp   s    z$InProcessKernelManagerTestCase.setUpc                 C   s   | j jr| j  ¡  d S r   )r   Ú
has_kernelÚshutdown_kernelr   r   r   r	   ÚtearDown   s    z'InProcessKernelManagerTestCase.tearDownc                 C   sÂ   | j }|jrJ ‚| ¡  |js"J ‚|jdus0J ‚| ¡ }|jrBJ ‚| ¡  |jsTJ ‚|j}| ¡  |  |j¡ |j|ks|J ‚| 	¡  |jrŽJ ‚|  
t|j¡ |  
t|jd¡ | ¡  |jr¾J ‚dS )zN Does the in-process kernel manager implement the basic KM interface?
        Né	   )r   r   Ústart_kernelÚkernelÚclientZchannels_runningÚstart_channelsZrestart_kernelZassertIsNotNoner   ZassertRaisesÚNotImplementedErrorZinterrupt_kernelZsignal_kernelZstop_channels)r   r   ÚkcZ
old_kernelr   r   r	   Útest_interface   s&    




z-InProcessKernelManagerTestCase.test_interfacec                 C   sJ   | j }| ¡  | ¡ }| ¡  | ¡  | d¡ |jjjd dksFJ ‚dS )z; Does executing code in an in-process kernel work?
        zfoo = 1Úfooé   N)	r   r   r   r   Úwait_for_readyÚexecuter   ÚshellÚuser_ns)r   r   r   r   r   r	   Útest_execute3   s    
z+InProcessKernelManagerTestCase.test_executec                 C   s‚   | j }| ¡  | ¡ }| ¡  | ¡  |jj dddœ¡ | dd¡ | 	¡ }|d d dksbJ ‚|  
t|d	 d
 ƒddg¡ dS )zD Does requesting completion from an in-process kernel work?
        r   r   )Úmy_barÚmy_bazZmy_baé   ÚheaderÚmsg_typeZcomplete_replyÚcontentZmatchesr   r   N)r   r   r   r   r   r   r   ÚpushZcompleteÚget_shell_msgZassertEqualÚsorted)r   r   r   Úmsgr   r   r	   Útest_complete>   s    ÿz,InProcessKernelManagerTestCase.test_completec                 C   sŠ   | j }| ¡  | ¡ }| ¡  | ¡  d|jjjd< | d¡ | 	¡ }|d d dksZJ ‚|d }|d snJ ‚|d d	 }|  
d
|¡ dS )zL Does requesting object information from an in-process kernel work?
        r   r   r    r!   Zinspect_replyr"   ÚfoundÚdataz
text/plainÚintN)r   r   r   r   r   r   r   r   Úinspectr$   ZassertIn)r   r   r   r&   r"   Útextr   r   r	   Útest_inspectM   s    
z+InProcessKernelManagerTestCase.test_inspectc                 C   s”   | j }| ¡  | ¡ }| ¡  | ¡  | d¡ |jddd |j ¡ d }|d d dks`J ‚|d	 d
 }t	|ƒdks|J ‚|d d dksJ ‚dS )zA Does requesting history from an in-process kernel work?
        Ú1Útailr   )Zhist_access_typeÚnéÿÿÿÿr    r!   Zhistory_replyr"   Úhistoryr   é   N)
r   r   r   r   r   r   r2   Zshell_channelZget_msgsÚlen)r   r   r   r&   r2   r   r   r	   Útest_history^   s    
z+InProcessKernelManagerTestCase.test_historyN)
Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r'   r-   r5   r   r   r   r	   r      s   r   Ú__main__)ZunittestZipykernel.inprocess.managerr   ZTestCaser   r6   Úmainr   r   r   r	   Ú<module>   s   c