a
    Nˆc   ã                   @   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	   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/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 nF t jyX   zt  t jd¡ W n t jyR   t d¡ Y n0 Y n0 t d¡ t 	¡ � t 
¡  W d   ƒ n1 sŠ0    Y  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   sb   | j }| j}tjtjdd|› d|› d|› d�g|¢i tj¥ddi¥|pHi ¥|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 ƒ �v}t|dƒ}|jddd� z$tj| dt|ƒg|tjtjd� W n& ttjfyj   Y W d  ƒ dS 0 W d  ƒ d	S 1 s‚0    Y  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   NFT)	r   r   Ú
write_textr    Ú
check_callÚstrÚDEVNULLÚOSErrorÚCalledProcessError)Z	texsystemZtmpdirZtex_pathr	   r	   r
   Ú_check_for_pgfR   s    	
ùþ
r5   c                 C   s2   zt j | › d�¡ W dS  ty,   Y dS 0 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    
