o
    û›hh  ã                   @   s   d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	m
Z
 ddlmZ ej dd	d
g¡dd„ ƒZedd„ ƒZe	d	d
ƒej dddg¡dd„ ƒƒZdd„ Zeefdd„ƒZej deeg¡ej dddg¡dd„ ƒƒZe
dd„ ƒZdd „ Zd!d"„ Zd#d$„ Ze
e	d	d
ƒd%d&„ ƒƒZd'd(„ ZdS ))zTests for IPython.utils.path.pyé    )Úcontextmanager)ÚpatchN)Ú
latextools)Úonlyif_cmds_existÚskipif_not_matplotlib©ÚFindCmdErrorÚcommandÚlatexÚdvipngc                    sT   ‡ fdd„}t  td|¡� t dd¡d u sJ ‚W d   ƒ d S 1 s#w   Y  d S )Nc                    s   | ˆ krt ‚d S ©Nr   )Úarg©r	   © úWc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/lib/tests/test_latextools.pyÚmock_find_cmd   s   ÿzGtest_check_latex_to_png_dvipng_fails_when_no_cmd.<locals>.mock_find_cmdZfind_cmdZwhateverT)r   Úobjectr   Úlatex_to_png_dvipng)r	   r   r   r   r   Ú0test_check_latex_to_png_dvipng_fails_when_no_cmd   s   "ÿr   c                  o   s   � d V  d S r   r   )ÚargsÚkwargsr   r   r   Úno_op   s   €
r   zs, wrap)z$$x^2$$F)úx^2Tc                 C   sN   dd„ }t  | |¡ t|ƒ� t  | |¡ W d  ƒ dS 1 s w   Y  dS )z@
    Test that latex_to_png_dvipng just runs without error.
    c                 S   ó   | dksJ ‚d S ©Nú	breqn.styr   ©Úfilenamer   r   r   Úmock_kpsewhich'   ó   z5test_latex_to_png_dvipng_runs.<locals>.mock_kpsewhichN)r   r   Úpatch_latextool)ÚsÚwrapr   r   r   r   Útest_latex_to_png_dvipng_runs!   s
   
"ÿr#   c                 C   r   r   r   r   r   r   r   r   1   r   r   c                 c   s<   � t  td| ¡� d V  W d   ƒ d S 1 sw   Y  d S )NZ	kpsewhich)r   r   r   )Zmockr   r   r   r    5   s   €"ÿr    ÚcontextÚs_wrap)ú$x^2$Fc                 C   sl   zddl }W n ty   t d¡ Y dS w | \}}|ƒ � t ||¡ W d  ƒ dS 1 s/w   Y  dS )z=
    Test that latex_to_png_mpl just runs without error.
    r   Nz%This needs matplotlib to be available)Ú
matplotlibÚImportErrorÚpytestÚskipr   Úlatex_to_png_mpl)r%   r$   r'   r!   r"   r   r   r   Útest_latex_to_png_mpl_runs:   s   
þ"ÿr,   c                  C   s   t  d¡} d| v sJ ‚d S )Nr&   zdata:image/png;base64,iVBOR)r   Zlatex_to_html)Zimgr   r   r   Útest_latex_to_htmlI   s   
r-   c                  C   óP   dd„ } t | ƒ� d t dd¡¡dksJ ‚W d  ƒ dS 1 s!w   Y  dS )z)
    Test genelatex with wrap=False.
    c                 S   s   J d  | ¡ƒ‚)NFz0kpsewhich should not be called (called with {0}))Úformatr   r   r   r   r   S   s   ÿz.test_genelatex_no_wrap.<locals>.mock_kpsewhichÚ
z	body textFz¡\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\pagestyle{empty}
\begin{document}
body text
\end{document}N©r    Újoinr   Z	genelatex©r   r   r   r   Útest_genelatex_no_wrapO   ó   
"ÿr4   c                  C   r.   )zL
    Test genelatex with wrap=True for the case breqn.sty is installed.
    c                 S   s   | dksJ ‚dS )Nr   zpath/to/breqn.styr   r   r   r   r   r   g   r   z6test_genelatex_wrap_with_breqn.<locals>.mock_kpsewhichr0   r   TzÊ\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{breqn}
\pagestyle{empty}
\begin{document}
\begin{dmath*}
x^2
\end{dmath*}
\end{document}Nr1   r3   r   r   r   Útest_genelatex_wrap_with_breqnc   r5   r6   c                  C   r.   )zP
    Test genelatex with wrap=True for the case breqn.sty is not installed.
    c                 S   r   r   r   r   r   r   r   r   ~   r   z9test_genelatex_wrap_without_breqn.<locals>.mock_kpsewhichr0   r   TzŸ\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\pagestyle{empty}
\begin{document}
$$x^2$$
\end{document}Nr1   r3   r   r   r   Ú!test_genelatex_wrap_without_breqnz   r5   r7   c                  C   s
  d} t j| dd�}t j| ddd�}t  | d¡}t  | dd¡}||ks$J ‚t  | d¡}t  | dd¡}||ks7J ‚|||fv s?J ‚|||fv sGJ ‚t  | dd¡}||ksTJ ‚t  | dd¡}||ksaJ ‚t  | dd¡}	t  | dd	¡}
|	|
ksuJ ‚t  | ddd
¡}|	|ksƒJ ‚dS )z/
    Test color settings for latex_to_png.
    r&   F)r"   z#000000)r"   ÚcolorZBlackZMaroonÚWhitez#FFFFFFg333333ó?N)r   Úlatex_to_pngr   r+   )Úlatex_stringÚdefault_valueZdefault_hexblackZdvipng_defaultZdvipng_blackZmpl_defaultZ	mpl_blackZdvipng_maroonZ
mpl_maroonZ	mpl_whiteZmpl_hexwhiteZmpl_white_scaler   r   r   Útest_latex_to_png_colorŽ   s4   ÿÿÿr=   c                      s0   d‰ t  t‡ fdd„¡ t  t‡ fdd„¡ dS )zM
    Test that invalid hex colors provided to dvipng gives an exception.
    r&   c                      ó   t jˆ ddd�S )Nr   z#f00bar©Úbackendr8   ©r   r:   r   ©r;   r   r   Ú<lambda>¹   s    ÿz6test_latex_to_png_invalid_hex_colors.<locals>.<lambda>c                      r>   )Nr   z#f00r?   rA   r   rB   r   r   rC   ¿   s    N)r)   ZraisesÚ
ValueErrorr   r   rB   r   Ú$test_latex_to_png_invalid_hex_colors²   s   
þ
þrE   )Ú__doc__Ú
contextlibr   Zunittest.mockr   r)   ZIPython.libr   ZIPython.testing.decoratorsr   r   ZIPython.utils.processr   ÚmarkZparametrizer   r   r#   r   r    r,   r-   r4   r6   r7   r=   rE   r   r   r   r   Ú<module>   s:    
	

"