B
    ]”t\%  ã               @   sj   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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 dd ¡}dt jd< |tjd< t ¡ }d| kr¶| 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| ddd
¡}| 
tddƒtddƒ¡|j
tddƒdgd tddƒd }| ddddg¡ d}	x"t||	ƒD ]\}
}|
 |¡ q*W d| krèdd
dgd
ddgddd
gg}| ddd¡j|dd ddd
gdd
dgddd
gg}| ddd¡j|dd d
ddgdd
dgd
ddgg}| ddd¡j|dd tdƒ}| ddd¡ 	||¡ ttjdtjƒ}|j||d |d kr>t j dd ¡ n
|t jd< d S ) NÚSOURCE_DATE_EPOCHZ	946684800ztext.usetexÚmé   é   é
   ÚD)Zmarkeré   Úxé   ú^é   ÚHé   ÚvÚh)Zbottomg      ø?g      @g      @g      @)ú-ú+r   ú\Ú*ÚoÚOÚ.ÚiZnearest)ZinterpolationZbilinearZbicubicÚbuffer)Úformat)ÚosÚenvironÚpopÚ
matplotlibZrcParamsÚpltZfigureZadd_subplotÚrangeZplotÚbarZ
set_xticksÚzipZ	set_hatchZimshowÚgetattrÚsysÚstdoutZsavefig)Úobjectsr   ÚusetexZsdeZfigZax1r   Zax2ZbarsZpatternsr$   ÚpatternÚAr(   © r-   ú=lib/python3.7/site-packages/matplotlib/testing/determinism.pyÚ_determinism_save   sD    


$

r/   c             C   s†   g }x:t dƒD ].}t tjddd|| ||f g¡}| |¡ qW x@|dd… D ]0}|rn||d kr~t 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Úpr-   r-   r.   Ú_determinism_checkG   s    r9   ó   CreationDatec          	   C   sh   t  tjddd| d| f g¡}t d| d ¡}| |¡}|rLt| ¡ ƒ 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)
r0   r1   r'   r2   ÚreÚcompileÚsearchÚprintÚgroupr6   )r   ÚstringÚkeywordZbuffZfind_keywordÚkeyr-   r-   r.   Ú_determinism_source_date_epochh   s    
rD   )r   r   F)r   r   F)r:   )Ú__doc__Úior   r<   r0   r'   r4   r!   r   r"   r/   r9   rD   r-   r-   r-   r.   Ú<module>   s   
6
!