Ë
    íÍ: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© ó    úp/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/matplotlib/testing/__init__.pyÚset_font_settings_for_testingr      s   € Ø"/„C‡L�L�ÑØ#,„C‡L�L�Ò r   c                  ó*   — dt         j                  d<   y )NÚ
matplotlibzsvg.hashsaltr	   r   r   r   Úset_reproducibility_for_testingr      s   € Ø#/„C‡L�L�Ò 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ô ‡G�GˆE„Nä	×	5Ñ	5Ó	7ñ Ü�‰Ô÷ô
 "Ô#Ü#Õ%øô! �<‰<ò 5ð	5Ü×ÑœVŸ]™]Ð,HÕIøÜ�|‰|ò 	5Ü�L‰Lð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Ñ&AˆF�?Ò#à�?Ó#¤z×'BÑ'BÑBÓ#ðÜ�~‰~Øð
ØØ 5Ø &Øñ	
ð  ñ	
ˆð$ ‡{‚{Ü�
‰
Ð)¨$¯+©+¨Ð7Ô8Ø‡{‚{Ü�
‰
Ð(¨¯©¨Ð6Ô7Ø€Køô! ò Ü�<‰<˜8Ò#ãØ�L‰L˜Ô(ØÜ×(Ñ(ò Ø�8Š8Ü�J‰JÐ-¨a¯h©h¨ZÐ8Ô9Ø�8Š8Ü�J‰JÐ,¨Q¯X©X¨JÐ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Ü%ä�N‰NØð>Ø>D¸ZÀrÈ$Èð Rð �h˜bð	"ð		
ð ð		
ð
Ü�j‰jð
à!$ô >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“ð Ø%+Ü!×)Ñ)´*×2DÑ2Dõ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:   € ðÜ�‰×!Ñ! W I¨TÐ"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à×Ñ˜R˜aÐ  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/   € ò
 Ðð ,ò ˆÜ�9‰9�WÕÙðð 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$   è ø€ ò %áˆAˆtð 	�‰��ñ%ù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Ü).¨u°fÓ)=Ö> Aœ˜Q�Ð>ÐÐ>Ü(-¨e°WÓ(=Ö> 1œ˜A�Ð>ÐÐ>Ü(-¨e°WÓ(=Ö> 1œ˜A�Ð>ÐÐ>Ü49¸'À7Ó4KÖ#L¨q¤C¨¥FÐ#LÐ Ð#LÜ�O‰O˜E D™LÓ)€EØŸ9™9ñ %ä ×(Ñ(ð,Ðð ,Ð"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   