ó
Ýà‹]c           @   s¤   d  d l  m Z d  d l Z d  d l Z d  d l m Z m Z d  d l Z d  d l m	 Z	 d  d l
 Z
 e j d d k Z d „  Z d Z d Z d	 „  Z d
 „  Z d S(   iÿÿÿÿ(   t   divisionN(   t   Popent   PIPE(   t   mkdtempi    i   c         C   sJ   t  j j ƒ  } | j |  ƒ t t j d d g d | d t rC t n d  ƒS(   Ns   -cs1   from jupyter_client.kernelapp import main; main()t   envt   stderr(
   t   ost   environt   copyt   updateR   t   syst
   executablet   PY3R   t   None(   t	   extra_envR   (    (    sB   lib/python2.7/site-packages/jupyter_client/tests/test_kernelapp.pyt   _launch   s
    	i
   c         C   s^   xW t  t t ƒ D]0 } |  j ƒ  d k	 r0 |  j St j d t ƒ q Wt d j	 t ƒ ƒ ‚ d S(   s-   Python 2 subprocess doesn't have timeouts :-(i   s!   Process didn't exit in {} secondsN(
   t   ranget	   WAIT_TIMEt	   POLL_FREQt   pollR   t
   returncodet   timet   sleept   AssertionErrort   format(   t   pt   _(    (    sB   lib/python2.7/site-packages/jupyter_client/tests/test_kernelapp.pyt
   hacky_wait   s    	c          C   sl  t  ƒ  }  t  ƒ  } t j j | d ƒ } z#t i |  d 6| d 6ƒ } xT t t t ƒ D]- } t j j | ƒ rq Pn  t	 j
 d t ƒ qU Wt d j t ƒ ƒ ‚ t j |  ƒ } t | ƒ d k sÂ t ‚ | d } | j d ƒ sá t ‚ | j d ƒ sö t ‚ | j ƒ  t r?| j d	 t ƒ \ } } | | j d
 d ƒ k sIt ‚ n
 t | ƒ Wd  t j |  ƒ t j | ƒ Xd  S(   Nt   startedt   JUPYTER_RUNTIME_DIRt*   JUPYTER_CLIENT_TEST_RECORD_STARTUP_PRIVATEi   s%   No started file created in {} secondsi    t   kernels   .jsont   timeouts   utf-8t   replace(   R   R   t   patht   joinR   R   R   R   t   isfileR   R   R   R   t   listdirt   lent
   startswitht   endswitht	   terminateR   t   communicatet   decodeR   t   shutilt   rmtree(   t   runtime_dirt   startup_dirR   R   R   t   filest   cfR   (    (    sB   lib/python2.7/site-packages/jupyter_client/tests/test_kernelapp.pyt   test_kernelapp_lifecycle    s0    			

!(   t
   __future__R    R   R,   t
   subprocessR   R   R
   t   tempfileR   R   t   version_infoR   R   R   R   R   R2   (    (    (    sB   lib/python2.7/site-packages/jupyter_client/tests/test_kernelapp.pyt   <module>   s   		
