
    ^j(                         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ZddlZddl	Z	ddl
mZ ddlZddlmZ  ej                  e      Zd Zd Zd Z	 	 	 dd	Zdd
dZd Zd Zd Zd Zd Zy)z
Helper functions for testing.
    N)Path)TemporaryDirectory)_apic                  P    dt         j                  d<   dt         j                  d<   y )NDejaVu Sanszfont.familydefaultztext.hintingmplrcParams     f/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/matplotlib/testing/__init__.pyset_font_settings_for_testingr      s    "/CLL#,CLL r   c                  *    dt         j                  d<   y )N
matplotlibzsvg.hashsaltr	   r   r   r   set_reproducibility_for_testingr      s    #/CLL r   c                     	 t        j                  t         j                  d       t        j                  d       t        j                         5  t        j                          d d d        t                t                y # t         j                  $ rW 	 t        j                  t         j                  d       n.# t         j                  $ r t        j                  d       Y nw xY wY w xY w# 1 sw Y   xY w)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   setupr      s    56 GGEN		5	5	7 
 "##%! << 5	5V]],HI|| 	5LL45	55 sA   $B C.C+$B:9C+:(C%"C+$C%%C+*C+.C7c           
      R   t         j                  dk(  rddl}	|	j                  d       |rt        j
                  x}}t         j                  dk(  r3d|vrt        j                  |d<   n|dxx   t        j                  z  cc<   	 t	        j                  | f||||||d|}
|
j                  r"t        j                  d
|
j                          |
j                  r"t        j                  d|
j                          |
S # t        $ r* t         j                  dk(  rddl}	|	j                  d	        t        j                  $ rc}|j                  r"t        j                  d
|j                          |j                  r"t        j                  d|j                          |d}~ww xY 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.skip
        If running on emscripten, which does not support subprocesses.
    pytest.xfail
        If platform is Cygwin and subprocess reports a fork() failure.
    
emscriptenr   Nz(emscripten does not support subprocesseswin32creationflagsenvtimeoutcheckstdoutstderrtextcygwinzFork failurezSubprocess output:
zSubprocess error:
)sysplatformpytestskip
subprocessPIPECREATE_NO_WINDOWrunBlockingIOErrorxfailCalledProcessErrorr'   r   errorr(   debug)commandr$   r%   r'   r(   r&   r)   capture_outputkwargsr-   proces               r   subprocess_run_for_testingr=   6   si   P |||#>?$//) ||w&(&0&A&AF?#?#z'B'BB#~~
5&	
  	
$ {{

)$++78{{

(67K!  <<8#LL((( 88JJ-ahhZ8988JJ,QXXJ78s   C? ?AF&AF!!F&)	extra_envc                J   | j                   }| j                  }| j                  j                  }t	        t
        j                  dd|d|d| dg|i t        j                  dt        j                  d|xs i |dt        j                  t        j                  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()0)SOURCE_DATE_EPOCH-SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MATPLOTLIBTr#   )__name__
__module____code__co_filenamer=   r+   
executableosenvironr
   __version__r/   r0   )funcr%   r>   argstargetmodulefiler;   s           r   subprocess_run_helperrQ      s     ]]F__F==$$D%NN>>DZr$ R hb	"		
 		

jj
!$ >A__
 B
 9D< Kr   c           	      V   t               5 }t        |d      }|j                  dd       	 t        j                  | ddt        |      g|t        j                  t        j                         	 ddd       y
# t        t        j                  f$ r Y ddd       y	w xY w# 1 sw Y   yxY w)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-errorz-no-shell-escape)cwdr'   r(   NFT)	r   r   
write_textr/   
check_callstrDEVNULLOSErrorr5   )	texsystemtmpdirtex_paths      r   _check_for_pgfr]      s     
	 
+   	 		!!,.@X %+!))*2D2DF #  667 	! 	 s/    BAA8.B8BBBBB(c                 t    	 t         j                  j                  |  d       y# t        t        f$ r Y yw xY w)Nz.styTF)r
   dvireadfind_tex_fileFileNotFoundErrorrY   )packages    r   _has_tex_packagerc      s:    !!WIT"23w' s   "% 77c                    dd l }|j                  d      }t        j                  dk(  r|j	                  d       |j
                  d d dk(  r| dk(  r|j	                  d       |j                         D ]  \  }}|j
                  d d	 |k\  s|} n d
}t        ddd|  d|gdd      }|j                  j                         j                  d d      sJ y )Nr   IPythonr!   z>Cannot change backend running IPython in subprocess on Windows   )      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=r@   T)r&   r9   ')r-   importorskipr+   r,   r.   version_infoitemsr=   r'   stripendswith)	"requested_backend_or_gui_frameworkall_expected_backendsr-   re   min_versionbackendexpected_backendcoder;   s	            r   ipython_in_subprocessrx      s    !!),G
||wTURa J..%7PQ !6 ; ; = W#{2&
LD% >?@$		
 	D ;;''!,<+=Q(?@@@r   c                  H    g d} | D ]  }t        j                  |      s y y)N)CICONTINUOUS_INTEGRATIONTRAVISCIRCLECIJENKINS	GITLAB_CIGITHUB_ACTIONSTEAMCITY_VERSIONTF)rI   getenv)ci_environment_variablesenv_vars     r   is_ci_environmentr      s/    
  , 99W r   c                    	 ddg} d}t        |d      D cg c]  }t        |       }}t        dd      D cg c]  }t        |       }}t        dd      D cg c]  }t        |       }}t        dd      D cg c]  }t        |       }}t        j                  |d	z
        	d
j	                  d t        j
                  g ||||	fd      D              }dt        j                   dt        j                   d
t        j                   dt        j                   d| d}| |fS c c}w c c}w c c}w c c}w )aZ  
    Generate text intended for use with multiple fonts to exercise font fallbacks.

    Returns
    -------
    fonts : list of str
        The names of the fonts used to render the test string, sorted by intended
        priority. This should be set as the font family for the Figure or Text artist.
    text : str
        The test string.
    cmr10r         i  iP  i  i    
c              3   D   K   | ]  \  }}d j                  |        yw) N)join).0_lines      r   	<genexpr>z'_gen_multi_font_text.<locals>.<genexpr>+  s$      %At 	%s    c                      t              dz  S )N    )next)xcounts    r   <lambda>z&_gen_multi_font_text.<locals>.<lambda>0  s    $u++ r   )keyzThere are basic characters
 z
and accented characters
z
in between!)rangechr	itertoolsr   r   groupbystringascii_uppercaseascii_lowercasedigitspunctuation)
fontsstartr   latin1_supplementlatin_extended_Alatin_extended_Bnon_basic_multilingual_planenon_basic_characterstest_strr   s
            @r   _gen_multi_font_textr     s]    m$E
 E).uf)=>AQ>>(-eW(=>1A>>(-eW(=>1A>>49'74K#LqCF#L #LOOEDL)E99 % ((, ,"2 ,5E ,*,+-%  &001 2q##$ %  	H (?) ?>>#Ls   D.D3D8<D=)N<   NNFTF)__doc__r   r   loggingrI   pathlibr   r   r/   r+   tempfiler   r   r
   r   	getLoggerrD   r   r   r   r   r=   rQ   r]   rc   rx   r   r   r   r   r   <module>r      s       	    
 '  w"-
0&2 FJ>B.3K\ ;? /d:AD*(r   