ó
 m[c           @` sÐ   d  Z  d d l m Z m Z m Z m 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 m Z d d e d „ Z d d e d	 „ Z d
 d „ Z d S(   u4   
Provides utilities to test output reproducibility.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   check_output(   t   pyplotu   mhiu   pdfc         C` s  t  j j d d  ƒ } d t  j d <| t j d <t j ƒ  } d |  k rü | j d d d ƒ } t	 d ƒ } | j
 | d g d d d	 ƒ| j
 | d
 g d d d ƒ| j
 | d g d d d ƒ| j
 | d g d d d ƒ| j
 | d g d d d ƒn  d |  k r¿| j d d d
 ƒ } | j t	 d d ƒ t	 d d ƒ ƒ | j t	 d d ƒ d g d d t	 d d ƒ ƒ} | j d d d d g ƒ d' }	 x- t | |	 ƒ D] \ }
 } |
 j | ƒ qŸWn  d |  k r²d d
 d g d
 d d g d d d
 g g } | j d d d ƒ j | d  d! ƒd d d
 g d d
 d g d d d
 g g } | j d d d ƒ j | d  d" ƒd
 d d g d d
 d g d
 d d g g } | j d d d ƒ j | d  d# ƒn  t	 d ƒ } | j d d d ƒ j
 | | ƒ t j r| d$ k rt j ƒ  } n t t j d% t j ƒ } | j | d& | ƒt j rZ| d$ k rZt j j | j ƒ  ƒ n  | d  k r|t  j j d d  ƒ n | t  j d <d  S((   Nu   SOURCE_DATE_EPOCHu	   946684800u   text.usetexu   mi   i   i
   t   markeru   Di   u   xi   u   ^i   u   Hi   u   vu   ht   bottomg      ø?g      @g      @g      @u   -u   +u   \u   *u   ou   Ou   .u   it   interpolationu   nearestu   bilinearu   bicubicu   psu   buffert   format(   u   -u   +u   xu   \u   *u   ou   Ou   .(   t   ost   environt   popt   Nonet
   matplotlibt   rcParamst   pltt   figuret   add_subplott   ranget   plott   bart
   set_xtickst   zipt	   set_hatcht   imshowt   sixt   PY2t   iot   StringIOt   getattrt   syst   stdoutt   savefigt   writet   getvalue(   t   objectsR	   t   usetext   sdet   figt   ax1t   xt   ax2t   barst   patternsR   t   patternt   AR    (    (    s=   lib/python2.7/site-packages/matplotlib/testing/determinism.pyt   _determinism_save   sL     !2*"*"*%c      
   C` s­   g  } xL t  d ƒ D]> } t t j d d d | |  | | f g ƒ } | j | ƒ q WxQ | d D]E } | r | | d k r¥ t j d ƒ q¥ q` | | d k s` t ‚ q` Wd S(	   uÃ  
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        contains characters corresponding to objects to be included in the test
        document: 'm' for markers, 'h' for hatch patterns, 'i' for images. The
        default value is "mhi", so that the test includes all these objects.
    format : str
        format string. The default value is "pdf".
    i   u   -Ru   -cu¦   import matplotlib; matplotlib._called_from_pytest = True; matplotlib.use(%r); from matplotlib.testing.determinism import _determinism_save;_determinism_save(%r,%r,%r)i   i    u+   failed, maybe due to ghostscript timestampsN(   R   R   R   t
   executablet   appendt   pytestt   skipt   AssertionError(   R$   R	   R%   t   plotst   it   resultt   p(    (    s=   lib/python2.7/site-packages/matplotlib/testing/determinism.pyt   _determinism_checkQ   s    t   CreationDatec         C` s‹   t  t j d d d |  d |  f g ƒ } t j d | d ƒ } | j | ƒ } | rg t | j ƒ  ƒ n t d | ƒ | | k s‡ t ‚ d S(   u  
    Test SOURCE_DATE_EPOCH support. Output a document with the environment
    variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
    document contains the timestamp that corresponds to this date (given as an
    argument).

    Parameters
    ----------
    format : str
        format string, such as "pdf".
    string : str
        timestamp string for 2000-01-01 00:00 UTC.
    keyword : bytes
        a string to look at when searching for the timestamp in the document
        (used in case the test fails).
    u   -Ru   -cu£   import matplotlib; matplotlib._called_from_pytest = True; matplotlib.use(%r); from matplotlib.testing.determinism import _determinism_save;_determinism_save(%r,%r)u    s   .*u!   Timestamp keyword (%s) not found!N(	   R   R   R0   t   ret   compilet   searcht   printt   groupR4   (   R	   t   stringt   keywordt   bufft   find_keywordt   key(    (    s=   lib/python2.7/site-packages/matplotlib/testing/determinism.pyt   _determinism_source_date_epochr   s    (   t   __doc__t
   __future__R    R   R   R   R   R   R
   R;   R   t
   subprocessR   R2   R   R   R   t   FalseR/   R9   RE   (    (    (    s=   lib/python2.7/site-packages/matplotlib/testing/determinism.pyt   <module>   s   ";!