ó
mÜJ]c           @` sB  d  d l  m Z m Z m Z m Z d  d l Z e 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 m Z m Z d  d l m Z m Z d  d	 l m Z d  d
 l m Z d  d l j j Z e j d d ƒ d „  ƒ Z e j  j! e j  j" d „  ƒ ƒ Z# e j  j! e j  j" d „  ƒ ƒ Z$ e j  j! e j  j" d „  ƒ ƒ Z% e j  j! e j  j" d „  ƒ ƒ Z& e j  j! e j  j" d „  ƒ ƒ Z' e j  j! e j  j" d „  ƒ ƒ Z( e j  j! e j  j" d „  ƒ ƒ Z) e j  j! e j  j" d „  ƒ ƒ Z* d „  Z+ d „  Z, d „  Z- e d ƒ d „  ƒ Z. d „  Z/ d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   patch(   t   Image(   t   row(   t   Plot(   t   ColumnDataSourcet   Range1dt   Rect(   t   webdriver_controlt   terminate_webdriver(   t   figure(   t	   Resourcest   scopeu   modulec          c` s   t  j ƒ  }  |  Vt |  ƒ d  S(   N(   R   t   createR   (   t   driver(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt	   webdriver*   s    c          C` sƒ   t  d t ƒ  d t ƒ  d d d d d d  d d  d d  d	 d  ƒ }  t j |  ƒ } | j d k sc t ‚ | j ƒ  d
 d k s t ‚ d  S(   Nt   x_ranget   y_ranget   plot_heighti   t
   plot_widtht   toolbar_locationt   outline_line_colort   background_fill_colort   border_fill_colors    i@  (   i   i   (   R   R	   t   Nonet   biet   get_screenshot_as_pngt   sizet   AssertionErrort   tobytes(   t   layoutt   png(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   test_get_screenshot_as_png8   s    	c          C` s_  t  d t d d ƒ d t d d ƒ d d d d d d  d	 d  d
 d  d d d d d d ƒ 
}  t d d d d d d d d d d d d ƒ } t d t d d g d d g ƒ ƒ } |  j | | ƒ t j |  ƒ } | j	 d  k sÜ t
 ‚ | j ƒ  } d } x@ t d ƒ D]2 } | | d | d d !d k rû | d 7} qû qû W| d k sCt
 ‚ t | ƒ d k s[t
 ‚ d  S(!   NR   i    i   R   R   i   R   R   R   R   t
   min_borderi   R   u   bluet   border_fill_alphat   xu   xt   yu   yt   widtht   heightt
   fill_coloru   redt
   line_colort   datag      à?i  i   s   ÿ  ÿi   i@  (   i   i   (   R   R	   R   R
   R   t   dictt	   add_glyphR   R   R   R   R    t   ranget   len(   R!   t   glypht   sourceR"   R,   t   countR&   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt%   test_get_screenshot_as_png_with_glyphE   s     $-$c         C` s   t  d t ƒ  d t ƒ  d d d d d d  d d  d d  d	 d  ƒ } t j | d
 |  ƒ} | j d k si t ‚ | j ƒ  d d j ƒ  k s‹ t ‚ d  S(   NR   R   R   i   R   R   R   R   R   R   u    i@  (   i   i   (	   R   R	   R   R   R   R   R   R    t   encode(   R   R!   R"   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt&   test_get_screenshot_as_png_with_driver]   s    	c         C` s|   t  d t ƒ  d t ƒ  d d d d d d  d d  d d  d	 d  ƒ } t j | d
 |  ƒ|  j ƒ  i d d 6d d 6k sx t ‚ d  S(   NR   R   R   i   R   R   R   R   R   R   iV  u   widthi   u   height(   R   R	   R   R   R   t   get_window_sizeR   (   R   R!   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt%   test_get_screenshot_as_png_large_plotk   s    	c      
   C` s[   t  d d ƒ } t j | d |  d t d d d t ƒ ƒ} t | j ƒ  ƒ d k sW t ‚ d  S(	   Nt   titleu.   ìœ ë‹ˆ ì½”ë“œ ì§€ì›ì„ìœ„í•œ ìž‘ì€ í…ŒìŠ¤íŠ¸R   t	   resourcest   modeu   inlinet   minifiedi    (   R   R   R   R   t   TrueR0   R    R   (   R   t   pR"   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt0   test_get_screenshot_as_png_with_unicode_minifiedy   s    *c      
   C` s[   t  d d ƒ } t j | d |  d t d d d t ƒ ƒ} t | j ƒ  ƒ d k sW t ‚ d  S(	   NR9   u.   ìœ ë‹ˆ ì½”ë“œ ì§€ì›ì„ìœ„í•œ ìž‘ì€ í…ŒìŠ¤íŠ¸R   R:   R;   u   inlineR<   i    (   R   R   R   R   t   FalseR0   R    R   (   R   R>   R"   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt2   test_get_screenshot_as_png_with_unicode_unminified   s    *c          C` sR   t  d t ƒ  d t ƒ  d d d d d d  ƒ }  t j |  ƒ } | g  k sN t ‚ d  S(   NR   R   R   i   R   R   (   R   R	   R   R   t   get_svgsR   (   R!   t   svgs(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   test_get_svgs_no_svg_present‰   s    c         C` sº   d „  } t  d t ƒ  d t ƒ  d d d d d d  d d  d	 d  d
 d d d ƒ 	} | t j | d |  ƒd ƒ } | t j | d |  ƒd ƒ } d } | | k s¤ t ‚ | | k s¶ t ‚ d  S(   Nc         S` s.   t  j d d |  ƒ }  t  j d d |  ƒ }  |  S(   Nu   id="\w{12}"u   id="X"u   url\(#\w{12}\)u   url(#X)(   t   ret   sub(   t   svg(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   fix_ids–   s    R   R   R   i   R   R   R   R   R   u   redt   output_backendu   svgR   i    un  <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20" style="width: 20px; height: 20px;"><defs/><g><g transform="scale(1,1) translate(0.5,0.5)"><rect fill="#FFFFFF" stroke="none" x="0" y="0" width="20" height="20"/><rect fill="red" stroke="none" x="5" y="5" width="10" height="10"/><g/></g></g></svg>(   R   R	   R   R   RB   R   (   R   RH   R!   t   svg0t   svg1t   svg2(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   test_get_svgs_with_svg_present’   s    	c       	   C` sz   d
 \ }  } t  d t ƒ  d t ƒ  d |  d | ƒ } t j | d d d	 d ƒ| j |  k sa t ‚ | j | k sv t ‚ d  S(   NiÈ   iú   R   R   R   R   R)   id   R(   (   iÈ   iú   (   R   R	   R   t   get_layout_htmlR   R   R   (   t   initial_heightt   initial_widthR!   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt%   test_get_layout_html_resets_plot_dims´   s    c          C` sQ   t  d t ƒ  d t ƒ  ƒ }  t j |  d d d d ƒt |  ƒ } t j | ƒ d  S(   NR   R   R)   id   R(   (   R   R	   R   RN   R   (   R>   R!   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   test_layout_html_on_child_first¿   s    c          C` sQ   t  d t ƒ  d t ƒ  ƒ }  t |  ƒ } t j | ƒ t j |  d d d d ƒd  S(   NR   R   R)   id   R(   (   R   R	   R   R   RN   (   R>   R!   (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt    test_layout_html_on_parent_firstÇ   s    u   PIL.Image.Imagec         C` sˆ   |  ƒ  } t  j | d d d d d d d d d	 d
 ƒ| j j d k sL t ‚ | j j d d k sh t ‚ | j j d i  k s„ t ‚ d  S(   Nt   leftu   leftt   rightu   rightt   topu   topt   bottomu   bottomt   extrai
   i   i    (   u   leftu   topu   rightu   bottom(   (   u   leftu   topu   rightu   bottom(   R   t   _crop_imaget   cropt
   call_countR   t	   call_args(   t
   mock_Imaget   image(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   test__crop_image_argsÓ   s
    	+c       	   C` sd   t  j d d d d ƒ }  t d d d d d	 d
 d d ƒ } t j |  |  } | j d k s` t ‚ d  S(   NR;   u   RGBAR   i
   RT   i   RU   i   RV   i   RW   i   i   i   (   i
   i
   (   i   i   (   R   t   newR-   R   RY   R   R   (   R^   t   rectt   cropped(    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   test__crop_imageÛ   s    !(0   t
   __future__R    R   R   R   t   pytestt   mockR   RE   t   PILR   t   bokeh.layoutsR   t   bokeh.models.plotsR   t   bokeh.modelsR   R	   R
   t   bokeh.io.webdriverR   R   t   bokeh.plottingR   t   bokeh.resourcesR   t   bokeh.io.exportt   iot   exportR   t   fixtureR   t   markt   unitt   seleniumR#   R4   R6   R8   R?   RA   RD   RM   RQ   RR   RS   R_   Rc   (    (    (    s9   lib/python2.7/site-packages/bokeh/io/tests/test_export.pyt   <module>   sD   " 								!			