3
$ßL]  ã               @   sb   d Z ddl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d„Z	dd	d
„Z
ddd„ZdS )z4
Provides utilities to test output reproducibility.
é    N)ÚpyplotÚmhiÚpdfFc             C   sL  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	� d| k�rB|jddd
ƒ}|j
tddƒtddƒƒ|j
tddƒdgd tddƒd� }|jddddgƒ d&}	x"t||	ƒD ]\}
}|
j|ƒ �q*W 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!� tdƒ}|jdddƒj	||ƒ ttjd$tjƒ}|j||d%� |d k�r>t jjdd ƒ n
|t jd< d S )'NZSOURCE_DATE_EPOCHZ	946684800ztext.usetexÚmé   é   é
   ÚD)Úmarkeré   Úxé   ú^é   ÚHé   ÚvÚh)Zbottomg      ø?g      @g      @g      @ú-ú+ú\Ú*ÚoÚOÚ.ÚiZnearest)ÚinterpolationZbilinearZbicubicÚbuffer)Úformat)r   r   r   r   r   r   r   r   )ÚosÚenvironÚpopÚ
matplotlibZrcParamsÚpltÚfigureZadd_subplotÚrangeZplotÚbarZ
set_xticksÚzipZ	set_hatchZimshowÚgetattrÚsysÚstdoutZsavefig)Úobjectsr   ÚusetexZsdeZfigZax1r   Zax2ZbarsÚpatternsr&   ÚpatternÚAr*   © r0   úF/tmp/pip-install-edjban26/matplotlib/matplotlib/testing/determinism.pyÚ_determinism_save   sD    


$

r2   c          
   C   s†   g }x:t dƒD ].}tjtjddd|| ||f gƒ}|j|ƒ qW x@|dd… D ]0}|rn||d kr~tjdƒ qN||d ksNt‚qNW dS )	aÃ  
    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".
    r   z-Rz-cz¨import matplotlib; matplotlib._called_from_pytest = True; matplotlib.use(%r); from matplotlib.testing.determinism import _determinism_save;_determinism_save(%r, %r, %r)r   Nr   z+failed, maybe due to ghostscript timestamps)	r%   Ú
subprocessÚcheck_outputr)   Ú
executableÚappendÚpytestÚskipÚAssertionError)r+   r   r,   Zplotsr   ÚresultÚpr0   r0   r1   Ú_determinism_checkF   s    r<   ó   CreationDatec             C   sh   t jtjddd| d| f gƒ}tjd| d ƒ}|j|ƒ}|rLt|jƒ ƒ ntd| ƒ ||ksdt	‚dS )a  
    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).
    z-Rz-cz¤import matplotlib; matplotlib._called_from_pytest = True; matplotlib.use(%r); from matplotlib.testing.determinism import _determinism_save;_determinism_save(%r, %r)Ú s   .*z!Timestamp keyword (%s) not found!N)
r3   r4   r)   r5   ÚreÚcompileÚsearchÚprintÚgroupr9   )r   ÚstringÚkeywordZbuffZfind_keywordÚkeyr0   r0   r1   Ú_determinism_source_date_epochg   s    
rG   )r   r   F)r   r   F)r=   )Ú__doc__r   r?   r3   r)   r7   r"   r   r#   r2   r<   rG   r0   r0   r0   r1   Ú<module>   s   
6
!