ó
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 m Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l j  j! j" Z" d d l# m$ Z$ m% Z% m& Z& d* Z' d+ Z( e j) d „  ƒ Z* e j) d „  ƒ Z+ d e f d „  ƒ  YZ, d d l- Z- d d l. m/ Z/ d „  Z0 e j) d „  ƒ Z1 d e2 f d  „  ƒ  YZ3 d! e2 f d" „  ƒ  YZ4 e j) ƒ  d# „  ƒ Z5 d$ e3 e4 f d% „  ƒ  YZ6 e j) ƒ  d& „  ƒ Z7 d' e6 e4 f d( „  ƒ  YZ8 e j) ƒ  d) „  ƒ Z9 d S(,   u<    Define a Pytest plugin for a Bokeh-specific testing tools

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   Thread(   t   ActionChains(   t   expected_conditions(   t   WebDriverWait(   t   gen(   t   IOLoop(   t   RequestHandler(   t   save(   t   Server(   t   INITt   RESULTSt   wait_for_canvas_resizeu   bokeh._testing.plugins.bokehu"   bokeh._testing.plugins.file_serveru   bokeh._testing.plugins.seleniumu   bokeh_app_infou   bokeh_model_pageu   bokeh_server_pageu   find_free_portu   output_file_urlu   single_plot_pageu   test_file_path_and_urlc         ` sŒ   d d l  m } |  j j d } |  j j ƒ  j | ƒ ‰  ˆ  j } | j d d ƒ } | | d d ƒ‡  f d †  } |  j	 | ƒ | j
 | ƒ S(	   Ni    (   t   output_fileu   .htmlu   \u   /t   modeu   inlinec           ` s   ˆ  j  ƒ  r ˆ  j ƒ  n  d  S(   N(   t   isfilet   remove(    (   t   file_obj(    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt	   tear_downL   s    (   t   bokeh.ioR   t   functiont   __name__t   fspatht   dirpatht   joint   strpatht   replacet   addfinalizert   where_is(   t   requestt   file_serverR   t   filenamet	   file_patht   urlR   (    (   R   s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   output_file_urlB   s    	c         ` sr   |  j  j d } |  j j ƒ  j | ƒ ‰  ˆ  j } | j d d ƒ } ‡  f d †  } |  j | ƒ | | j | ƒ f S(   Nu   .htmlu   \u   /c           ` s   ˆ  j  ƒ  r ˆ  j ƒ  n  d  S(   N(   R   R   (    (   R   (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyR   Z   s    (	   R   R   R   R   R   R   R   R   R   (   R    R!   R"   R#   R$   R   (    (   R   s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   test_file_path_and_urlS   s    	t   _ExitHandlerc           B` s#   e  Z d  „  Z e j d „  ƒ Z RS(   c         C` s   | |  _  d  S(   N(   t   io_loop(   t   selfR(   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt
   initializec   s    c         O` s   |  j  j ƒ  d  S(   N(   R(   t   stop(   R)   t   argst   kwargs(    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   gete   s    (   R   t
   __module__R*   R   t	   coroutineR.   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyR'   b   s   	(   t   closingc          C` sF   t  t j t j t j ƒ ƒ " }  |  j d ƒ |  j ƒ  d SWd  QXd  S(   Nu    i    i   (   u    i    (   R1   t   sockett   AF_INETt   SOCK_STREAMt   bindt   getsockname(   t   s(    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   find_free_portm   s    !c         ` s   ‡  ‡ f d †  } | S(   u?   Start a Bokeh server app and return information needed to test it.

    Returns a tuple (url, message_test_port), where the latter is defined as

        namedtuple('MessageTestPort', ['sent', 'received'])

    and will contain all messages that the Bokeh Server sends/receives while
    running during the test.

    c         ` sž   d d l  m } | d d d g ƒ } | g  g  ƒ t _ t ƒ  ‰ ‡  ‡ f d †  } t d | ƒ ‰ ˆ j ƒ  ‡ ‡ ‡ f d †  } ˆ j | ƒ d	 ˆ t j f S(
   Ni    (   t
   namedtupleu   MessageTestPortu   sentu   receivedc          ` s^   t  ƒ  }  t i ˆ  d 6d ˆ d |  d d t t d |  ƒ f g ƒ} | j ƒ  | j j ƒ  d  S(   Nu   /t   portR(   t   extra_patternsu   /exit(   R	   R   R'   t   dictt   startR(   (   R(   t   server(   t
   modify_docR:   (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   worker…   s    	
t   targetc           ` s5   ˆ  j  d ˆ ƒ ˆ  j d ƒ d  t _ ˆ j ƒ  d  S(   Nu   http://localhost:%d/exitu   browser(   R.   t   get_logt   Nonet   wst   _message_test_portR   (    (   t   driverR:   t   t(    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   cleanup‘   s    	u   http://localhost:%d/(   t   collectionsR9   RD   RE   R8   R   R=   R   (   R?   R9   t   MessageTestPortR@   RH   (   RF   R    (   R?   R:   RG   s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   func   s    		

(    (   R    RF   RK   (    (   RF   R    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   bokeh_app_infor   s     t   _BokehModelPagec           B` sh   e  Z d  „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z d	 d „ Z
 d „  Z d „  Z RS(
   c         C` sF   | |  _  | |  _ | |  _ t |  j ƒ |  j  j | ƒ |  j ƒ  d  S(   N(   t   _drivert   _modelt   _has_no_console_errorsR   R.   t   init_results(   R)   t   modelRF   R%   t   has_no_console_errors(    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   __init__£   s    			c         C` sJ   t  |  j d ƒ j t j |  j ƒ ƒ |  j j d ƒ |  _ |  j j t ƒ S(   Ni
   u   bokeh-test-div(	   R   RN   t   untilt   ECt   staleness_oft   test_divt   find_element_by_class_namet   execute_scriptR   (   R)   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   results®   s    %c         C` s   |  j  S(   N(   RN   (   R)   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRF   ´   s    c         C` s)   |  j  j t ƒ |  j  j d ƒ |  _ d  S(   Nu   bokeh-test-div(   RN   RZ   R   RY   RX   (   R)   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRQ   ¸   s    c         C` s:   t  |  j ƒ } | j | | | ƒ | j ƒ  | j ƒ  d  S(   N(   R   RN   t   move_to_element_with_offsett   clickt   perform(   R)   t   elementt   xt   yt   actions(    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   click_element_at_position¼   s    
c         C` sD   t  |  j ƒ } | j | | | ƒ | j ƒ  | j ƒ  | j ƒ  d  S(   N(   R   RN   R\   R]   R^   (   R)   R_   R`   Ra   Rb   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt    double_click_element_at_positionÂ   s
    

c         C` s€   t  |  j ƒ } | r% | j | ƒ n  | j | | | ƒ | j ƒ  | j | | ƒ | j ƒ  | rr | j | ƒ n  | j ƒ  d  S(   N(	   R   RN   t   key_downR\   t   click_and_holdt   move_by_offsett   releaset   key_upR^   (   R)   R_   R`   Ra   t   dxt   dyt   modRb   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   drag_element_at_positionÉ   s    

c         G` s*   t  |  j ƒ } | j | Œ  | j ƒ  d  S(   N(   R   RN   t	   send_keysR^   (   R)   t   keysRb   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRn   Õ   s    c         C` s   |  j  |  j ƒ S(   N(   RP   RN   (   R)   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRS   Ú   s    N(   R   R/   RT   t   propertyR[   RF   RQ   Rc   Rd   RC   Rm   Rn   RS   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRM   ¡   s   					t   _CanvasMixinc           B` s8   e  Z d  „  Z d „  Z d „  Z d d „ Z d „  Z RS(   c         C` s   |  j  |  j | | ƒ d  S(   N(   Rc   t   canvas(   R)   R`   Ra   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   click_canvas_at_positionà   s    c         C` s   |  j  |  j | | ƒ d  S(   N(   Rd   Rr   (   R)   R`   Ra   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   double_click_canvas_at_positionã   s    c         C` s    |  j  j d ƒ } | j ƒ  d  S(   Nu   bk-toolbar-button-custom-action(   RN   RY   R]   (   R)   t   button(    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   click_custom_actionæ   s    c         C` s#   |  j  |  j | | | | | ƒ d  S(   N(   Rm   Rr   (   R)   R`   Ra   Rj   Rk   Rl   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   drag_canvas_at_positionê   s    c         C` s   |  j  j d | ƒ S(   Nu   bk-tool-icon-(   RF   RY   (   R)   t   name(    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   get_toolbar_buttoní   s    N(   R   R/   Rs   Rt   Rv   RC   Rw   Ry   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRq   Þ   s
   			c         ` s   ‡  ‡ ‡ f d †  } | S(   Nc         ` s   t  |  ˆ  ˆ ˆ ƒ S(   N(   RM   (   RR   (   RF   RS   R%   (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRK   ó   s    (    (   RF   R%   RS   RK   (    (   RF   RS   R%   s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   bokeh_model_pageñ   s    t   _SinglePlotPagec           B` s   e  Z d  „  Z RS(   c         C` sK   t  t |  ƒ j | | | | ƒ |  j j d ƒ |  _ t |  j |  j ƒ d  S(   Nu   canvas(   t   superR{   RT   RN   t   find_element_by_tag_nameRr   R   (   R)   RR   RF   R%   RS   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRT   û   s    (   R   R/   RT   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyR{   ø   s   c         ` s   ‡  ‡ ‡ f d †  } | S(   Nc         ` s   t  |  ˆ  ˆ ˆ ƒ S(   N(   R{   (   RR   (   RF   RS   R%   (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRK     s    (    (   RF   R%   RS   RK   (    (   RF   RS   R%   s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   single_plot_page  s    t   _BokehServerPagec           B` s   e  Z d  „  Z RS(   c         C` s€   | |  _  | |  _ | | ƒ \ |  _ |  _ t j d ƒ |  j  j |  j ƒ |  j ƒ  |  j  j d ƒ |  _	 t
 |  j	 |  j  ƒ d  S(   Ngš™™™™™¹?u   canvas(   RN   RP   t   _app_urlt   message_test_portt   timet   sleepR.   RQ   R}   Rr   R   (   R)   R?   RF   RL   RS   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRT     s    		
(   R   R/   RT   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyR   	  s   c         ` s   ‡  ‡ ‡ f d †  } | S(   Nc         ` s   t  |  ˆ ˆ  ˆ ƒ S(   N(   R   (   R?   (   RL   RF   RS   (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyRK     s    (    (   RF   RL   RS   RK   (    (   RL   RF   RS   s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   bokeh_server_page  s    (   u   bokeh._testing.plugins.bokehu"   bokeh._testing.plugins.file_serveru   bokeh._testing.plugins.selenium(   u   bokeh_app_infou   bokeh_model_pageu   bokeh_server_pageu   find_free_portu   output_file_urlu   single_plot_pageu   test_file_path_and_url(:   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggerR   t   logR‚   t	   threadingR   t   pytestt'   selenium.webdriver.common.action_chainsR   t   selenium.webdriver.supportR   RV   t   selenium.webdriver.support.uiR   t   tornadoR   t   tornado.ioloopR	   t   tornado.webR
   R   R   t   bokeh.server.serverR   t   bokeh.server.views.wsR>   t   viewsRD   t   bokeh._testing.util.seleniumR   R   R   t   pytest_pluginst   __all__t   fixtureR%   R&   R'   R2   t
   contextlibR1   R8   RL   t   objectRM   Rq   Rz   R{   R~   R   R„   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/plugins/bokeh.pyt   <module>	   sP   "        	/=
