o
    Ďih                     @   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	    ]/home/jeff/fluffinator/venv/lib/python3.10/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_cmdfind_cmd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 )N	kpsewhich)r   r   r   )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   
"r0   c                  C   s   t d} d| v sJ d S )Nr*   zdata:image/png;base64,iVBOR)r   latex_to_html)imgr   r   r   test_latex_to_htmlI   s   
r3   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   	genelatexr    r   r   r   test_genelatex_no_wrapO      
"r;   c                  C   r4   )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_kpsewhichr6   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}Nr7   r:   r   r   r   test_genelatex_wrap_with_breqnc   r<   r=   c                  C   r4   )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_kpsewhichr6   r   Tz\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\pagestyle{empty}
\begin{document}
$$x^2$$
\end{document}Nr7   r:   r   r   r   !test_genelatex_wrap_without_breqnz   r<   r>   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sJ dS )z/
    Test color settings for latex_to_png.
    r*   F)r$   z#000000)r$   colorBlackMaroonWhitez#FFFFFFg333333?N)r   latex_to_pngr   r/   )latex_stringdefault_valuedefault_hexblackdvipng_defaultdvipng_blackmpl_default	mpl_blackdvipng_maroon
mpl_maroon	mpl_whitempl_hexwhitempl_white_scaler   r   r   test_latex_to_png_color   s4   rP   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backendr?   r   rC   r   rD   r   r   <lambda>   s    z6test_latex_to_png_invalid_hex_colors.<locals>.<lambda>c                      rQ   )Nr   z#f00rR   rT   r   rU   r   r   rV      s    N)r-   raises
ValueErrorr   r   rU   r   $test_latex_to_png_invalid_hex_colors   s   

rY   )__doc__
contextlibr   unittest.mockr   r-   IPython.libr   IPython.testing.decoratorsr   r   IPython.utils.processr   markparametrizer   r   r%   r    r"   r0   r3   r;   r=   r>   rP   rY   r   r   r   r   <module>   s:    
	

"