o
    h                     @   s.  d 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m	Z	 ddl
mZ ddlmZ ddlmZ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dlZddlmZ ddlmZ dddZ ej!"dddddddej#dddeegdddej#dddedg
d d! Z$ej!"d"d#d$gd%d& Z%dS )'z
Test output reproducibility.
    N)pyplot)get_sample_data)PathCollection)	BboxImage)AnchoredOffsetboxAuxTransformBox)Circle	PathPatch)Path)subprocess_run_for_testing)needs_ghostscriptneeds_usetex)TextPath)IdentityTransformmhippdfFc              	   C   s  t | t jd|d t }d| v rX|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| v r|ddd	}|	tddtdd|j	tdddgd tddd }|
g d d}t||D ]	\}	}
|	|
 qd| v rg dg dg dg}|dddj|dd g dg dg dg}|dddj|dd g dg dg dg}|dddj|dd d| v rG d d! d!t}|jd"d#}|d	gg}|td$d%d& |d	\}}ttd'}td(d)d*d+}|||d,d-}tt }|| td.|d/d0d1}|| t  }| jd9  _| jd	8  _t  }|jd d d2 |_t||}td }| jd39  _|jd	d	d/d/d4\}}||fD ]B}|\}}t |gdd5d6d7d8d9}|||j! |"| t|dd5d6d7d8d9}|||j! |#| |$d:dg |%d:dg q}td}|ddd}||| |&d; |'d; |(d; t)t*j+d<t*j+}|j,||d= d S )>Nasdf)zsvg.hashsaltztext.usetexm      
   D)marker   x   ^   H   vh)bottom)g      ?g      @g      @g      @)-+r   \*oO.i)r   r   r   )r   r   r   )r   r   r   nearest)interpolation)r   r   r   bilinear)r   r   r   bicubicpc                       s:   e Zd ZdZ fddZ fddZd	 fdd	Z  ZS )
z+_save_figure.<locals>.PathClippedImagePatchz
            The given image is used to draw the face of the patch. Internally,
            it uses BboxImage whose clippath set to the path of the patch.

            FIXME : The result is currently dpi dependent.
            c                    s6   t  j|fi | t| jd d d| _| j| d S )N)normorigin)super__init__r   get_window_extent
bbox_imageset_data)selfpathr5   kwargs	__class__ u/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/matplotlib/tests/test_determinism.pyr3   H   s
   z4_save_figure.<locals>.PathClippedImagePatch.__init__c                    s   t  d dS )zSimply ignore facecolor.noneN)r2   set_facecolor)r7   colorr:   r<   r=   r?   N   s   z9_save_figure.<locals>.PathClippedImagePatch.set_facecolorNc                    s0   | j | j|   | j | t | d S N)r5   set_clip_path_pathget_transformdrawr2   )r7   rendererr:   r<   r=   rE   R   s   z0_save_figure.<locals>.PathClippedImagePatch.drawrA   )__name__
__module____qualname____doc__r3   r?   rE   __classcell__r<   r<   r:   r=   PathClippedImagePatch@   s
    rL   polar)
projection)r   r   gioT?)radiuszgrace_hopper.jpg)r   r   z!?   )sizek)ecz
upper leftTg?)locchildframeon	borderpadg@)sharexshareyblueredgffffff?r&   )lw	edgecolor	facecoloralphahatchzA string $1+2+\sigma$buffer)format)-mplusercParamsupdatepltfigureadd_subplotrangeplotbar
set_xtickszip	set_hatchimshowr	   rB   r   subplotsimreadr   r   r   r   
add_artistr   r
   unit_rectangledeepcopyverticesunit_circlemake_compound_pathunit_regular_starr   	transDataadd_collection	add_patchset_xlimset_ylim	set_title
set_xlabel
set_ylabelgetattrsysstdoutsavefig)objectsfmtusetexfigax1r   ax2barspatternsrn   patternArL   pxpimgarr	text_pathr/   	offsetboxaoexteriorinterior	clip_pathstarrow1row2row
collectionpatchaxr   r<   r<   r=   _save_figure   s   
 










r   zobjects, fmt, usetex) r   F)r   r   F)r!   r   F)r*   r   F)r   r   F)r   psFr   T)marks)r/   svgF)r   r   Fr   c                    sd    fddt dD }|dd D ]} dkr'r'||d kr&td q||d ks/J qdS )	aR  
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        Objects to be included in the test document: 'm' for markers, 'h' for
        hatch patterns, 'i' for images, and 'p' for paths.
    fmt : {"pdf", "ps", "svg"}
        Output format.
    c                    sN   g | ]#}t tjd ddd d dgi tjddddd	d	d
jqS )-R-czHfrom matplotlib.tests.test_determinism import _save_figure;_save_figure(z, )	946684800AggSOURCE_DATE_EPOCH
MPLBACKENDFT)envtextcapture_outputcheckr   r   
executableosenvironr   ).0_r   r   r   r<   r=   
<listcomp>   s&    
z*test_determinism_check.<locals>.<listcomp>r   r   Nr   r   z+failed, maybe due to ghostscript timestamps)rl   pytestskip)r   r   r   plotsr/   r<   r   r=   test_determinism_check   s   

r   zfmt, string)r   s!   /CreationDate (D:20000101000000Z))r   s(   %%CreationDate: Sat Jan 01 00:00:00 2000c                 C   sF   t tjddd| dgi tjddddd	dd
j}||v s!J 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
    ----------
    fmt : {"pdf", "ps", "svg"}
        Output format.
    string : bytes
        Timestamp string for 2000-01-01 00:00 UTC.
    r   r   zMfrom matplotlib.tests.test_determinism import _save_figure; _save_figure('', r   r   r   r   TF)r   r   r   r   Nr   )r   stringbufr<   r<   r=   "test_determinism_source_date_epoch   s   
r   )&rJ   r   r   r   
matplotlibre   r   ri   matplotlib.cbookr   matplotlib.collectionsr   matplotlib.imager   matplotlib.offsetboxr   r   matplotlib.patchesr   r	   matplotlib.pathr
   matplotlib.testingr   matplotlib.testing._markersr   r   matplotlib.testing.comparematplotlib.textr   matplotlib.transformsr   r   markparametrizeparamr   r   r<   r<   r<   r=   <module>   sT    
u

