ó
mÜJ]c           @` sÖ   d  Z  d d l m Z m Z m Z m Z d d l Z e j e  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 m Z d d l m Z d Z d Z e j d d	  d
    Z d S(   u3    Define a Pytest plugin to provide a Bokeh server

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   ConnectionError(   t   writeu   bokeh._testing.plugins.log_fileu   bokeh_servert   scopeu   sessionc         ` sh  |  j  j j } d d d d g } d | g } d |   t j j   } d | d <y) t j | | d	 | d
 | d |  Wn9 t k
 rľ t	 d d j
 | |   t j d  nŻ X f d   } |  j |  d d d       f d   } |   s*t	 d d j
 | |   t j d  n   j d  k	 r`t	 d t  j   t j d  n    Sd  S(   Nu   pythonu   -mu   bokehu   serveu	   --port=%su   http://localhost:%su   falseu   BOKEH_MINIFIEDt   envt   stdoutt   stderru   Failed to run: %su    i   c           ` s   t  d    j   d  S(   Nu   Shutting down bokeh-server ...(   R   t   kill(    (   t   proc(    sB   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh_server.pyt   stop_bokeh_serverG   s    
g      @g{ŽGáz?c         S` sQ   t  j    } x> t rL |    r" t St  j    | | k r< t St  j |  q Wd  S(   N(   t   timet   Truet   Falset   sleep(   t   funct   timeoutt   intervalt   start(    (    sB   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh_server.pyt
   wait_untilL   s    		c          ` s      f d   }   |   S(   Nc           ` s=    j  d  k	 r t Sy t j    SWn t k
 r8 t SXd  S(   N(   t
   returncodet   NoneR   t   requestst   getR   R   (    (   t   bokeh_server_urlR   (    sB   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh_server.pyt   helperW   s    (    (   R   (   R   R   R   (    sB   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh_server.pyt   wait_for_bokeh_serverV   s    u   Timeout when running: %su   bokeh server exited with code (   t   configt   optiont
   bokeh_portt   ost   environt   copyt
   subprocesst   Popent   OSErrorR   t   joint   syst   exitt   addfinalizerR   R   t   str(   t   requestt   log_fileR   t   cmdt   argvR   R   R   (    (   R   R   R   sB   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh_server.pyt   bokeh_server5   s,    

)
	(   u   bokeh._testing.plugins.log_file(   u   bokeh_server(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logR    R#   R'   R   t   pytestR   t   requests.exceptionsR   t   bokeh.util.terminalR   t   pytest_pluginst   __all__t   fixtureR/   (    (    (    sB   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh_server.pyt   <module>	   s   "