U
    Fvf                     @   s   d Z ddlmZ ddl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
Zddl
mZ eeZdd Zdd	 Zd
d ZddddZdd Zdd ZdS )z
Helper functions for testing.
    )Path)TemporaryDirectoryN)_apic                   C   s"   dt jd< dt jd< dt jd< d S )NzDejaVu Sanszfont.familynoneztext.hinting   ztext.hinting_factormplZrcParams r	   r	   ?/tmp/pip-unpacked-wheel-7vhvci0g/matplotlib/testing/__init__.pyset_font_settings_for_testing   s    

r   c                   C   s   dt jd< d S )N
matplotlibzsvg.hashsaltr   r	   r	   r	   r
   set_reproducibility_for_testing   s    r   c                   C   s   zt t jd W nJ t jk
r\   zt t jd W n  t jk
rV   td Y nX Y nX td t	  t
  W 5 Q R X t  t  d S )Nzen_US.UTF-8zEnglish_United States.1252zPCould not set locale to English/United States. Some date-related tests may fail.ZAgg)locale	setlocaleLC_ALLError_logwarningr   Zuser   Z'suppress_matplotlib_deprecation_warningZ
rcdefaultsr   r   r	   r	   r	   r
   setup   s    

r   )	extra_envc             
   G   s\   | j }| j}tjtjdd| d| d| df|tjddi|pBi |dtjtjdd	}|S )
a  
    Run a function in a sub-process.

    Parameters
    ----------
    func : function
        The function to be run.  It must be in a module that is importable.
    *args : str
        Any additional command line arguments to be passed in
        the first argument to ``subprocess.run``.
    extra_env : dict[str, str]
        Any additional environment variables to be set for the subprocess.
    z-czfrom z import z; z()SOURCE_DATE_EPOCH0T)envtimeoutcheckstdoutstderruniversal_newlines)	__name__
__module__
subprocessrunsys
executableosenvironPIPE)funcr   r   argstargetmoduleprocr	   r	   r
   subprocess_run_helper5   s"     
r,   c              
   C   s   t  t}t|d}|jddd z$tj| dt|g|tjtjd W n& ttjfk
rj   Y W 5 Q R  dS X W 5 Q R  dS Q R X d	S )
z
    Check if a given TeX system + pgf is available

    Parameters
    ----------
    texsystem : str
        The executable name to check
    ztest.texz
            \documentclass{article}
            \usepackage{pgf}
            \begin{document}
            \typeout{pgfversion=\pgfversion}
            \makeatletter
            \@@end
        zutf-8)encodingz-halt-on-error)cwdr   r   FTN)	r   r   
write_textr    
check_callstrDEVNULLOSErrorCalledProcessError)Z	texsystemZtmpdirZtex_pathr	   r	   r
   _check_for_pgfR   s    	
  
r5   c                 C   s4   zt j|  d W dS  tk
r.   Y dS X d S )Nz.styTF)r   ZdvireadZ_find_tex_fileFileNotFoundError)packager	   r	   r
   _has_tex_packagen   s
    r8   )__doc__pathlibr   tempfiler   r   loggingr$   r    r"   r   r   r   	getLoggerr   r   r   r   r   r,   r5   r8   r	   r	   r	   r
   <module>   s    
