ó
mÜJ]c           @` sm  d  d l  m Z m Z m Z m Z d  d l Z e 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 Z d  d l Z d  d l j j j Z d  d l m Z d „  Z d „  Z d „  Z d „  Z d	 „  Z e j d
 „  ƒ Z d „  Z d „  Z d „  Z  e j! j" e j# d d ƒd „  ƒ Z$ e j! j" e j# d d ƒd „  ƒ Z% d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   sleep(   t   DEFAULT_SERVER_PORTc          C` sM   d d  l  }  d d l m } t j d |  j ƒ  ƒ } t | | ƒ sI t ‚ d  S(   Ni    (   t
   Subcommandt   parser(   t   argparset   bokeh.command.subcommandR   t   scservet   Servet   ArgumentParsert
   isinstancet   AssertionError(   R   R   t   obj(    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   test_create1   s    c           C` s   t  j d k s t ‚ d  S(   Nu   traceu   debugu   infou   warningu   erroru   critical(   u   traceu   debugu   infou   warningu   erroru   critical(   R
   t	   LOGLEVELSR   (    (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   test_loglevels8   s    c           C` s   t  j j d k s t ‚ d  S(   Nu   serve(   R
   R   t   nameR   (    (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt	   test_name;   s    c           C` s   t  j j d k s t ‚ d  S(   Nu3   Run a Bokeh server hosting one or more applications(   R
   R   t   helpR   (    (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt	   test_help>   s    c       #   C` s  d d l  m }  t j j d t d d d t d d d	 t ƒ f d
 t d d d t d d d	 d  ƒ f d t d d d d d	 d d t j
 d d |  t j
 ƒ ƒ f d t d d d d d	 t j d d t j j d d ƒ ƒ f d t d d d d d	 d  d d ƒ f d t d d d d d d  d	 d  ƒ f d! t d d" d t j d d# ƒ f d$ t d d% d d d	 d  d t d d d d& ƒ f d' t d d( d d) ƒ f d* t d d+ d d, d t d d- ƒ f d. t d d/ d t d d0 d	 d  ƒ f d1 t d d2 d t d d3 d	 d  ƒ f d4 t d d2 d t d d5 d	 d  ƒ f d6 t d d2 d t d d7 d	 d  ƒ f d8 t d d2 d t d d9 d	 d  ƒ f d: t d d2 d t d d; d	 d  ƒ f d< t d d( d d= ƒ f d> t d d? d d d	 d  d t j d d |  t j ƒ ƒ f d@ t d dA d d d	 d  d dB ƒ f dC t d d( d dD ƒ f dE t d d( d dF ƒ f dG t d dH d d d dI d	 dJ d t ƒ f dK t d dL d d d dM d	 dQ d t ƒ f f k s‹t ‚ d  S(R   Ni    (   t	   nice_joinu   --portt   metavaru   PORTt   typeR   u   Port to listen ont   defaultu	   --addressu   ADDRESSu   Address to listen onu   --log-levelu	   LOG-LEVELt   actionu   storeu   infot   choicesu
   One of: %su   --log-formatu
   LOG-FORMATu5   A standard Python logging format string (default: %r)u   %u   %%u
   --log-fileu   LOG-FILEuT   A filename to write logs to, or None to write to the standard stream (default: None)u   filesu   DIRECTORY-OR-SCRIPTt   nargsu   *uO   The app directories or scripts to serve (serve empty document if not specified)u   --argsu   COMMAND-LINE-ARGSuÓ   Command line arguments remaining to passed on to the application handler. NOTE: if this argument precedes DIRECTORY-OR-SCRIPT then some other argument, e.g --show, must be placed before the directory or script. u   --devu   FILES-TO-WATCHu  Enable live reloading during app development. By default it watches all *.py *.html *.css *.yaml files in the app directory tree. Additional files can be passed as arguments.NOTE: if this argument precedes DIRECTORY-OR-SCRIPT then some other argument, e.g --show, must be placed before the directory or script. NOTE: This setting only works with a single app. It also restricts the number of processes to 1. NOTE FOR WINDOWS USERS : this option must be invoked using 'python -m bokeh'. If not Tornado will fail to restart the serveru   --showu
   store_trueu   Open server app(s) in a browseru   --allow-websocket-originu   HOST[:PORT]u   appendu9   Public hostnames which may connect to the Bokeh websocketu   --prefixu   PREFIXu    URL prefix for Bokeh server URLsu   --keep-aliveu   MILLISECONDSu=   How often to send a keep-alive ping to clients, 0 to disable.u   --check-unused-sessionsu&   How often to check for unused sessionsu   --unused-session-lifetimeu   How long unused sessions lastu   --stats-log-frequencyu   How often to log statsu   --mem-log-frequencyu)   How often to log memory usage informationu   --use-xheadersu,   Prefer X-headers for IP/protocol informationu   --session-idsu   MODEu   --indexu   INDEXu,   Path to a template to use for the site indexu   --disable-indexu-   Do not use the default index on the root pathu   --disable-index-redirectu-   Do not redirect to running app from root pathu   --num-procsu   Nu^   Number of worker processes for an app. Using 0 will autodetect number of cores (defaults to 1)i   u   --websocket-max-message-sizeu   BYTESuw   Set the Tornado websocket_max_message_size value (defaults to 20MB) NOTE: This setting has effect ONLY for Tornado>=4.5i   i   i P  i  @(   t   bokeh.util.stringR   R
   R   t   argst   dictt   intR   t   strt   NoneR   t   DEFAULT_LOG_FORMATt   replaceR   t	   REMAINDERt   SESSION_ID_MODESR   (   R   (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt	   test_argsA   sä    																																															c         c` sÖ   t  j d d d g |  } t j | d t j d t j ƒ} y	 | VWnx t k
 r½ } | j ƒ  | j ƒ  t	 d | ƒ y- | j
 j ƒ  j ƒ  } t	 d ƒ t	 | ƒ Wn t k
 r¶ n X‚  n X| j ƒ  | j ƒ  d  S(   Nu   -mu   bokehu   servet   stdoutt   stderru   An error occurred: %su%   
---- subprocess stdout follows ----
(   t   syst
   executablet
   subprocesst   Popent   PIPEt   STDOUTt	   Exceptiont	   terminatet   waitt   printR)   t   readt   decode(   R   t   cmdt   pt   et   out(    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   run_bokeh_serveó   s"    !	



c         C` sˆ   t  j d d d g |  } y t j | d t j ƒWn: t j k
 ro } | j d k s] t ‚ | j j	 ƒ  } n Xt
 j d | f ƒ | S(   Nu   -mu   bokehu   serveR*   i   u    command %s unexpected successful(   R+   R,   R-   t   check_outputR0   t   CalledProcessErrort
   returncodeR   t   outputR6   t   pytestt   fail(   R   R7   R9   R:   (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   check_error  s    c          C` s>   t  d ƒ }  t d |  g ƒ } d |  } | | k s: t ‚ d  S(   Nu   8.8.8.8u	   --addressu3   Cannot start Bokeh server, address %r not available(   R"   RB   R   (   t   hostR:   t   expected(    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   test_host_not_available  s    
c          C` ss   t  j  ƒ  }  zU |  j d ƒ |  j ƒ  d } t d t | ƒ g ƒ } d | } | | k s` t ‚ Wd  |  j ƒ  Xd  S(   Nu   0.0.0.0i    i   u   --portu4   Cannot start Bokeh server, port %d is already in use(   u   0.0.0.0i    (   t   sockett   bindt   getsocknameRB   R"   R   t   close(   t   sockt   portR:   RD   (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   test_port_not_available  s    
t   reasonu%   Travis bug causes bad file descriptorc       	   C` s4  d d l  m  }  m } m } d d l m } m } t j d ƒ } d  } t	 d d g ƒ Õ } |  | j
 | ƒ } |  | j
 | | | Bƒ t d ƒ | | j
 j ƒ  d ƒ }	 | j |	 j ƒ  ƒ } | d  k rØ t j d
 ƒ n  t | j d ƒ ƒ }
 |
 d k sÿ t ‚ t j d |
 f ƒ } | j d k s*t ‚ Wd  QXd  S(   Ni    (   t   fcntlt   F_GETFLt   F_SETFL(   t
   O_NONBLOCKR5   u,   Bokeh app running at: http://localhost:(\d+)u   --portu   0i   id   i   u&   no matching log line in process outputi   u   http://localhost:%d/iÈ   i  (   RN   RO   RP   t   osRQ   R5   t   ret   compileR#   R;   R)   R   t   filenot   searchR6   R@   RA   R!   t   groupR   t   requestst   gett   status_code(   RN   RO   RP   RQ   R5   t   patt   mR8   t   flagst   oRK   t   r(    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   test_actual_port_printed_out$  s     
c          C` s{   t  j d ƒ }  t d d g ƒ  } t d ƒ Wd  QX| j ƒ  \ } } |  j | j ƒ  ƒ } | d  k rw t j	 d ƒ n  d  S(   Nu0   Torndado websocket_max_message_size set to 12345u   --websocket-max-message-sizeu   12345i   u&   no matching log line in process output(
   RS   RT   R;   R   t   communicateRV   R6   R#   R@   RA   (   R[   R8   R^   R9   R\   (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt+   test_websocket_max_message_size_printed_out7  s    (&   t
   __future__R    R   R   R   R@   R   t
   contextlibRS   RF   R-   R+   t   timeR   RX   t   sixt   bokeh.command.subcommands.servet   commandt   subcommandst   serveR
   t   bokeh.resourcesR   R   R   R   R   R(   t   contextmanagerR;   RB   RE   RL   t   markt   skipift   PY2R`   Rb   (    (    (    sI   lib/python2.7/site-packages/bokeh/command/subcommands/tests/test_serve.pyt   <module>   s0   " 					²			$