ó
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
 m Z d d l Z d d l m Z d Z d	 „  Z e j d
 d ƒ d „  ƒ Z e j d
 d ƒ d „  ƒ Z d S(   u0    Define a Pytest plugin for a log file fixture

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   warn(   t	   webdriveru   driveru   has_no_console_errorsu   pytest_report_collectionfinishc         C` sD   |  j  d d ƒ j ƒ  } | d k r* d n d } d d | | f g S(   u   

    u   driveru   chromeu   ONu   OFFu    uF   Bokeh selenium tests using %r driver (no-console-error assertions: %s)(   t	   getoptiont   lower(   t   configt   startdirt   itemst   drivert   asserts(    (    s>   lib/python2.7/site-packages/bokeh/_testing/plugins/selenium.pyt   pytest_report_collectionfinish.   s    t   scopeu   sessionc         c` s  |  j  d d ƒ j ƒ  } | d k ry d d l m } | ƒ  } | j d ƒ | j d ƒ | j d ƒ t j d | ƒ } no | d	 k rÍ d d l m } | ƒ  } | j d ƒ | j d ƒ t j d
 | ƒ } n | d k rè t j	 ƒ  } n  | j
 d ƒ | V| j ƒ  d S(   uG    Select and configure a Selenium webdriver for integration tests.

    u   driveru   chromei    (   t   Optionsu
   --headlessu   --no-sandboxu   --window-size=1920x1080t   chrome_optionsu   firefoxt   firefox_optionsu   safarii
   N(   R   R   t!   selenium.webdriver.chrome.optionsR   t   add_argumentR   t   Chromet"   selenium.webdriver.firefox.optionst   Firefoxt   Safarit   implicitly_waitt   quit(   t   pytestconfigt   driver_nameR   t   optionsR   (    (    s>   lib/python2.7/site-packages/bokeh/_testing/plugins/selenium.pyR   6   s&    		c         C` s:   |  j  d ƒ j ƒ  } | d k r- d „  } n	 d „  } | S(   u   Provide a function to assert no browser console errors are present.

    Unfortunately logs are only accessibly with Chrome web driver, see e.g.

        https://github.com/mozilla/geckodriver/issues/284

    For non-Chrome webdrivers this check always returns True.

    u   driveru   chromec         S` s¹   |  j  d ƒ } g  | D]! } | j d ƒ d k r | ^ q } g  | D]! } | j d ƒ d k rD | ^ qD } t | ƒ d k r¤ t | ƒ d k r  t d | ƒ n  t St j d | ƒ d  S(	   Nu   browseru   levelu   SEVEREu   typeu   networki    uR   There were severe network errors (this may or may not have affected your test): %su   Console errors: %s(   t   get_logt   gett   lenR   t   Truet   pytestt   fail(   R   t   logst   xt   severe_errorst   lt   non_network_errors(    (    s>   lib/python2.7/site-packages/bokeh/_testing/plugins/selenium.pyt   funcd   s    ..c         S` s   t  S(   N(   R    (   R   (    (    s>   lib/python2.7/site-packages/bokeh/_testing/plugins/selenium.pyR(   r   s    (   R   R   (   R   R   R(   (    (    s>   lib/python2.7/site-packages/bokeh/_testing/plugins/selenium.pyt   has_no_console_errorsU   s
    	(   u   driveru   has_no_console_errorsu   pytest_report_collectionfinish(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logt   warningsR   R!   t   seleniumR   t   __all__R   t   yield_fixtureR   t   fixtureR)   (    (    (    s>   lib/python2.7/site-packages/bokeh/_testing/plugins/selenium.pyt   <module>	   s   "	  	