ó
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 m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l Z d d l m Z m Z d d l m Z d d l Z d d l m Z d d l m  Z  m! Z! d d	 l" m# Z# d d
 l$ m% Z% d d l& m' Z' m( Z( d Z) d e* f d „  ƒ  YZ+ d e* f d „  ƒ  YZ, d d d d d d d „ Z. d „  Z/ d „  Z0 d S(   u4    Provide support modules for testing Bokeh itself.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(	   t   joint   existst   dirnamet   basenamet   normpatht   relpatht   splitextt   isfilet   isdir(   t   Popent   PIPE(   t	   b64decode(   t   __version__(   t   S3_URLt   upload_file_to_s3(   t   JOB_ID(   t
   image_diff(   t   tracet   greenu   add_examplesu   collect_examplesu   Exampleu   Flagst   Flagsc           B` s>   e  Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z	 d Z
 RS(   i   i    i   i   i   i   i   i   i   i   i   i   i   i   i    i@   i€   i   (   t   __name__t
   __module__t   jst   filet   servert   notebookt   slowt   skipt   xfailt   no_jst   no_diff(    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR   8   s   t   Examplec           B` s6  e  Z d  „  Z d „  Z e Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z  e d „  ƒ Z! e d „  ƒ Z" e d „  ƒ Z# e d  „  ƒ Z$ e d! „  ƒ Z% e d" „  ƒ Z& d# „  Z' d$ „  Z( d% „  Z) e d& „  ƒ Z* d' „  Z+ RS((   c         C` s[   t  | ƒ |  _ | |  _ | |  _ d  |  _ t |  _ d |  _ d  |  _	 d  |  _
 t |  _ d  S(   Ni    (   R   t   patht   flagst   examples_dirt   Nonet	   _diff_reft   Falset   _uploadt   pixelst   _has_reft   _has_baselinet   Truet   _baseline_ok(   t   selfR$   R%   R&   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   __init__E   s    							c      	   C` sÌ   |  j  r d n d |  j r! d n d |  j r3 d n d |  j rE d n d |  j rW d n d |  j ri d n d |  j r{ d n d |  j r d	 n d |  j rŸ d
 n d g	 } d |  j	 d j
 d „  | Dƒ ƒ f S(   Nu   jsu    u   fileu   serveru   notebooku   slowu   skipu   xfailu   no_jsu   no_diffu   Example(%r, %s)u   |c         s` s   |  ] } | r | Vq d  S(   N(    (   t   .0t   f(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pys	   <genexpr>]   s    (   t   is_jst   is_filet	   is_servert   is_notebookt   is_slowt   is_skipR    R!   R"   R	   R   (   R0   R%   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   __str__P   s    c         C` s   t  |  j ƒ S(   N(   R   t   path_no_ext(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   namea   s    c         C` s   t  |  j ƒ S(   N(   R   R$   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   base_dire   s    c         C` s   t  t |  j ƒ d ƒ S(   Nu   .tests(   R   R   R$   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   imgs_diri   s    c         C` s   t  |  j |  j ƒ S(   N(   R	   R$   R&   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR	   m   s    c         C` s   t  |  j ƒ d S(   Ni    (   R
   R$   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR;   q   s    c         C` s   t  |  j ƒ d S(   Ni    (   R
   R	   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   relpath_no_extu   s    c         C` s   |  j  t j @S(   N(   R%   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR4   y   s    c         C` s   |  j  t j @S(   N(   R%   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR5   }   s    c         C` s   |  j  t j @S(   N(   R%   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR6      s    c         C` s   |  j  t j @S(   N(   R%   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR7   …   s    c         C` s   |  j  t j @S(   N(   R%   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR8   ‰   s    c         C` s   |  j  t j @S(   N(   R%   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR9      s    c         C` s   |  j  t j @S(   N(   R%   R   R    (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   is_xfail‘   s    c         C` s   |  j  t j @S(   N(   R%   R   R!   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR!   •   s    c         C` s   |  j  t j @S(   N(   R%   R   R"   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR"   ™   s    c         C` s   |  j  o |  j S(   N(   t   has_baselineR/   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   baseline_ok   s    c         C` s   t  d d t |  j d ƒ ƒ S(   Nu   testsu	   baselinesu    (   R   R	   R;   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   baseline_path¡   s    c         C` sc   |  j  d  k r\ d d d |  j g } t | d t d t ƒ} | j ƒ  | j d k |  _  n  |  j  S(   Nu   gitu   showu   :%st   stdoutt   stderri    (   R-   R'   RC   R   R   t   communicatet
   returncode(   R0   t   cmdt   proc(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRA   ¥   s    
c         C` sc   |  j  } t t | ƒ ƒ s1 t j t | ƒ ƒ n  t j | d d d ƒ } | j | ƒ Wd  QXd  S(   Nu   wt   newlineu   
(   RC   R   R   t   ost   makedirst   iot   opent   write(   R0   t   baselineR$   R3   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   store_baseline°   s
    	c         C` sÌ   d d d d d |  j  g } t | d t d t ƒ} | j ƒ  \ } } | j d k rY d  Sd	 d
 g } t | d t d t d t ƒ} | j | ƒ \ } } | j d k r° | } n  t |  _ | j d ƒ j	 ƒ  S(   Nu   gitu   diffu   --coloru   --exit-codeu   %sRD   RE   i    u   perlu8   /usr/share/doc/git/contrib/diff-highlight/diff-highlightt   stdinu   utf-8(
   RC   R   R   RF   RG   R'   R)   R/   t   decodet   strip(   R0   RH   RI   t   difft   _t   hl_diff(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   diff_baseline·   s    		c         C` s   |  j  s |  j S|  j S(   N(   R*   t   img_patht   img_url(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   img_path_or_urlÉ   s    c         C` s   |  j  s |  j S|  j S(   N(   R*   t   ref_patht   ref_url(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   ref_path_or_urlÍ   s    c         C` s   |  j  s |  j S|  j S(   N(   R*   t	   diff_patht   diff_url(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   diff_path_or_urlÑ   s    c         C` s    t  |  j d |  j t t f ƒ S(   Nu   %s-%s-%s.png(   R   R>   R<   R   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRY   Õ   s    c         C` s#   t  |  j d |  j |  j t f ƒ S(   Nu   %s-%s-%s.png(   R   R>   R<   R(   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR\   Ù   s    c         C` s&   t  |  j d |  j t |  j t f ƒ S(   Nu   %s-%s-%s-diff-%s.png(   R   R>   R<   R   R(   R   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR_   Ý   s    c         C` s   t  t |  j ƒ S(   N(   R   R   t   img_url_path(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRZ   á   s    c         C` s   t  t |  j ƒ S(   N(   R   R   t   ref_url_path(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR]   å   s    c         C` s   t  t |  j ƒ S(   N(   R   R   t   diff_url_path(   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR`   é   s    c         C` s   t  d d t |  j ƒ d S(   Nu   travisu
   image_refsu   .png(   R   R   R?   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRb   í   s    c         C` s   t  d d |  j |  j ƒ d S(   Nu   travisu
   image_refsu   .png(   R   R(   R?   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRc   ñ   s    c         C` s!   t  d d t |  j ƒ |  j d S(   Nu   travisu
   image_refsu	   -diff.png(   R   R   R?   R(   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRd   õ   s    c         C` s   |  j  S(   N(   R,   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   has_refù   s    c         C` sV   |  j  d  k rO t j |  j ƒ } | j |  _  | j rO t |  j | j ƒ qO n  |  j  S(   N(	   R,   R'   t   requestst   getR]   t   okt   _store_binaryR\   t   content(   R0   t   response(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt	   fetch_refý   s    	c         C` s   t  |  j t | ƒ ƒ d  S(   N(   Ri   RY   R   (   R0   t   img_data(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt	   store_img  s    c         C` sŽ   t  |  j ƒ rE t d t d ƒ |  j f ƒ t |  j |  j d ƒ n  t  |  j ƒ rŠ t d t d ƒ |  j f ƒ t |  j |  j d ƒ n  d  S(   Nu   %s Uploading image to S3 to %su   >>>u	   image/png(   R   RY   R   R   R   Rb   R_   Rd   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   upload_imgs
  s    c         C` s   |  j  d k S(   Ni    (   R+   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   images_differ  s    c         C` s%   t  |  j |  j |  j ƒ |  _ |  j S(   N(   R   R_   RY   R\   R+   (   R0   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR     s    (,   R   R   R1   R:   t   __repr__t   propertyR<   R=   R>   R	   R;   R?   R4   R5   R6   R7   R8   R9   R@   R!   R"   RB   RC   RA   RQ   RX   R[   R^   Ra   RY   R\   R_   RZ   R]   R`   Rb   Rc   Rd   Re   Rl   Rn   Ro   Rp   R   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyR#   C   sR   					
			c	         C` s-  | j  d ƒ r t | | d  ƒ }	 xd t t j |	 ƒ ƒ D]M }
 t t |	 |
 ƒ ƒ r8 t |  t | d  |
 ƒ | | | | | | | ƒ	 q8 q8 Wd  St | | ƒ } xŠt t j | ƒ ƒ D]s}
 d } |
 } |
 j d ƒ rÙ q² n2|
 j  d ƒ r| | r÷ | n t j	 O} n|
 j  d ƒ r#| t j
 O} nè t t | |
 ƒ ƒ r² t t | |
 |
 d ƒ ƒ rƒt |
 |
 d ƒ }
 | | rv| n t j O} qt t | |
 |
 d ƒ ƒ rÎt |
 |
 d ƒ }
 | | rÁ| n t j	 O} qt t | |
 d	 ƒ ƒ r² | | rõ| n t j O} qq² n q² | d  k	 r3| | k r3| t j O} n  | d  k	 rg| d
 k sW| | k rg| t j O} n  | d  k	 r›| d
 k s‹| | k r›| t j O} n  | d  k	 rÏ| d
 k s¿| | k rÏ| t j O} n  | d  k	 r| d
 k só| | k r| t j O} n  |  j t t | |
 ƒ | | ƒ ƒ q² Wd  S(   Nu   *iÿÿÿÿi    u   _u   .u   .pyu   .ipynbu   .htmlu   main.pyu   all(   u   _u   .(   t   endswithR   t   sortedRK   t   listdirR   t   add_examplest
   startswithR   R   R   R   R   R   R'   R   R   R    R!   R"   t   appendR#   (   t   list_of_examplesR$   R&   t   example_typeR   R   R    R!   R"   t	   star_pathR<   t   example_pathR%   t	   orig_name(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRv     sL    6$$$$c         C` s  t  |  ƒ } g  } t |  d ƒ  } t j | j ƒ  ƒ } Wd  QXxÈ | D]À } | d } | j d ƒ d  k	 r t t | d ƒ } n d  } | j d ƒ } | j d ƒ }	 | j d ƒ }
 | j d ƒ } | j d ƒ } t	 | | | d	 | d
 | d |	 d |
 d | d | ƒqF W| S(   Nu   ru   pathu   typeu   slowu   skipu   xfailu   no_jsu   no_diffRz   R   R   R    R!   R"   (
   R   RN   t   yamlt	   safe_loadt   readRg   R'   t   getattrR   Rv   (   t   config_pathR&   Ry   R3   t   examplest   exampleR$   Rz   t   slow_statust   skip_statust   xfail_statust   no_js_statust   no_diff_status(    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   collect_examplesR  s"    
)c         C` sQ   t  |  ƒ } t | ƒ s( t j | ƒ n  t |  d ƒ  } | j | ƒ Wd  QXd  S(   Nu   wb(   R   R   RK   RL   RN   RO   (   R$   t   datat	   directoryR3   (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyRi   s  s
    (   u   add_examplesu   collect_examplesu   Exampleu   Flags(1   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggerR   t   logRM   RK   t   os.pathR   R   R   R   R   R	   R
   R   R   R~   t
   subprocessR   R   t   base64R   Rf   t   bokeh._testing.util.gitR   t   bokeh._testing.util.s3R   R   t   bokeh._testing.util.travisR   t   bokeh._testing.util.imagesR   t   bokeh.util.terminalR   R   t   __all__t   objectR   R#   R'   Rv   RŠ   Ri   (    (    (    s;   lib/python2.7/site-packages/bokeh/_testing/util/examples.pyt   <module>	   s0   "@   Ø7	!