o
    h                     @   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ZddddZdd Z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mplrcParams r
   r
   o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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 n# t jy,   z	t t jd W n t jy)   td Y nw Y nw td t	  t
  W d    n1 sEw   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.Agg)locale	setlocaleLC_ALLError_logwarningr   user   'suppress_matplotlib_deprecation_warning
rcdefaultsr   r   r
   r
   r
   r   setup   s$   



r   <   FTc           
   	   C   sZ   |rt j }}zt j| ||||||d}W |S  ty,   tjdkr+ddl}	|	d  w )a  
    Create and run a subprocess.

    Thin wrapper around `subprocess.run`, intended for testing.  Will
    mark fork() failures on Cygwin as expected failures: not a
    success, but not indicating a problem with the code either.

    Parameters
    ----------
    args : list of str
    env : dict[str, str]
    timeout : float
    stdout, stderr
    check : bool
    text : bool
        Also called ``universal_newlines`` in subprocess.  I chose this
        name since the main effect is returning bytes (`False`) vs. str
        (`True`), though it also tries to normalize newlines across
        platforms.
    capture_output : bool
        Set stdout and stderr to subprocess.PIPE

    Returns
    -------
    proc : subprocess.Popen

    See Also
    --------
    subprocess.run

    Raises
    ------
    pytest.xfail
        If platform is Cygwin and subprocess reports a fork() failure.
    envtimeoutcheckstdoutstderrtextcygwinr   NzFork failure)
subprocessPIPErunBlockingIOErrorsysplatformpytestxfail)
commandr   r   r   r    r   r!   capture_outputprocr)   r
   r
   r   subprocess_run_for_testing5   s    &


r.   )	extra_envc             
   G   sh   | j }| j}| jj}ttjdd|d|d| dg|i tjddi|p'i |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.
    -czEimport importlib.util;_spec = importlib.util.spec_from_file_location(z, z]);_module = importlib.util.module_from_spec(_spec);_spec.loader.exec_module(_module);_module.z()SOURCE_DATE_EPOCH0Tr   )__name__
__module____code__co_filenamer.   r'   
executableosenvironr#   r$   )funcr   r/   argstargetmodulefiler-   r
   r
   r   subprocess_run_helperm   s.   
r?   c              
   C   s   t  <}t|d}|jddd ztj| dt|g|tjtjd W n ttjfy5   Y W d   dS w 	 W d   d	S 1 sBw   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)	texsystemtmpdirtex_pathr
   r
   r   _check_for_pgf   s    	

$rK   c                 C   s.   zt j|  d W dS  ty   Y dS w )Nz.styTF)r   dvireadfind_tex_fileFileNotFoundError)packager
   r
   r   _has_tex_package   s   rP   c           	      C   s   dd l }|d}tjdkr|d |jd d dkr%| dkr%|d | D ]\}}|jd d	 |kr:|} nq)d
}tddd|  d|gddd}|j	 
d| dsZJ d S )Nr   IPythonwin32z>Cannot change backend running IPython in subprocess on Windows   )r      r   osxz:Bug using macosx backend in IPython 8.24.0 fixed in 8.24.1   zpimport matplotlib as mpl, matplotlib.pyplot as plt;fig, ax=plt.subplots(); ax.plot([1, 3, 2]); mpl.get_backend()ipythonz--no-simple-promptz--matplotlib=r0   T)r   r,   ')r)   importorskipr'   r(   skipversion_infoitemsr.   r   stripendswith)	"requested_backend_or_gui_frameworkall_expected_backendsr)   rQ   min_versionbackendexpected_backendcoder-   r
   r
   r   ipython_in_subprocess   s.   



 re   c                  C   s&   g d} | D ]
}t |r dS qdS )N)CICONTINUOUS_INTEGRATIONTRAVISCIRCLECIJENKINS	GITLAB_CIGITHUB_ACTIONSTEAMCITY_VERSIONTF)r8   getenv)ci_environment_variablesenv_varr
   r
   r   is_ci_environment   s   
rq   )Nr   NNFTF)__doc__pathlibr   tempfiler   r   loggingr8   r#   r'   r   r   r   	getLoggerr3   r   r   r   r   r.   r?   rK   rP   re   rq   r
   r
   r
   r   <module>   s.    

8%"