##// END OF EJS Templates
Add `delete` binding for clearing auto-suggestion (#13990)...
Add `delete` binding for clearing auto-suggestion (#13990) Closes #13987 assuming that we have a consensus.

File last commit:

r27639:c55dbf99
r28193:c14f8408 merge
Show More
test_latextools.py
192 lines | 5.6 KiB | text/x-python | PythonLexer
/ IPython / lib / tests / test_latextools.py
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 """Tests for IPython.utils.path.py"""
Min RK
remove testing.tools.monkeypatch...
r21116 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800
from contextlib import contextmanager
Srinivas Reddy Thatiparthy
remove code specific to python2
r23063 from unittest.mock import patch
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800
import pytest
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
from IPython.lib import latextools
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 from IPython.testing.decorators import (
onlyif_cmds_exist,
skipif_not_matplotlib,
)
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 from IPython.utils.process import FindCmdError
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 @pytest.mark.parametrize('command', ['latex', 'dvipng'])
def test_check_latex_to_png_dvipng_fails_when_no_cmd(command):
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 def mock_find_cmd(arg):
if arg == command:
raise FindCmdError
Min RK
remove testing.tools.monkeypatch...
r21116 with patch.object(latextools, "find_cmd", mock_find_cmd):
Matthias Bussonnier
== None to is None
r26721 assert latextools.latex_to_png_dvipng("whatever", True) is None
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 @contextmanager
def no_op(*args, **kwargs):
yield
@onlyif_cmds_exist("latex", "dvipng")
Matthias Bussonnier
typo and reformat
r27639 @pytest.mark.parametrize("s, wrap", [("$$x^2$$", False), ("x^2", True)])
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 def test_latex_to_png_dvipng_runs(s, wrap):
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 """
Test that latex_to_png_dvipng just runs without error.
"""
def mock_kpsewhich(filename):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert filename == "breqn.sty"
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 return None
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 latextools.latex_to_png_dvipng(s, wrap)
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 with patch_latextool(mock_kpsewhich):
latextools.latex_to_png_dvipng(s, wrap)
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800
def mock_kpsewhich(filename):
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 assert filename == "breqn.sty"
return None
Thomas Kluyver
Fix IPython.lib.latextools for Python 3
r8013
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 @contextmanager
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 def patch_latextool(mock=mock_kpsewhich):
with patch.object(latextools, "kpsewhich", mock):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 yield
Thomas Kluyver
Fix IPython.lib.latextools for Python 3
r8013
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 @pytest.mark.parametrize('context', [no_op, patch_latextool])
@pytest.mark.parametrize('s_wrap', [("$x^2$", False), ("x^2", True)])
def test_latex_to_png_mpl_runs(s_wrap, context):
"""
Test that latex_to_png_mpl just runs without error.
"""
try:
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 import matplotlib
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 except ImportError:
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 pytest.skip("This needs matplotlib to be available")
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 return
s, wrap = s_wrap
with context():
latextools.latex_to_png_mpl(s, wrap)
Thomas Kluyver
Fix IPython.lib.latextools for Python 3
r8013
@skipif_not_matplotlib
def test_latex_to_html():
img = latextools.latex_to_html("$x^2$")
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert "data:image/png;base64,iVBOR" in img
Thomas Kluyver
Fix IPython.lib.latextools for Python 3
r8013
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
def test_genelatex_no_wrap():
"""
Test genelatex with wrap=False.
"""
def mock_kpsewhich(filename):
assert False, ("kpsewhich should not be called "
"(called with {0})".format(filename))
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 with patch_latextool(mock_kpsewhich):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert '\n'.join(latextools.genelatex("body text", False)) == r'''\documentclass{article}
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 \usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\pagestyle{empty}
\begin{document}
body text
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 \end{document}'''
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
def test_genelatex_wrap_with_breqn():
"""
Test genelatex with wrap=True for the case breqn.sty is installed.
"""
def mock_kpsewhich(filename):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert filename == "breqn.sty"
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 return "path/to/breqn.sty"
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 with patch_latextool(mock_kpsewhich):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert '\n'.join(latextools.genelatex("x^2", True)) == r'''\documentclass{article}
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 \usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{breqn}
\pagestyle{empty}
\begin{document}
\begin{dmath*}
x^2
\end{dmath*}
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 \end{document}'''
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858
def test_genelatex_wrap_without_breqn():
"""
Test genelatex with wrap=True for the case breqn.sty is not installed.
"""
def mock_kpsewhich(filename):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert filename == "breqn.sty"
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 return None
Matthias Bussonnier
Remove yield test that are not support by pytest anymore...
r26183 with patch_latextool(mock_kpsewhich):
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert '\n'.join(latextools.genelatex("x^2", True)) == r'''\documentclass{article}
Takafumi Arakaki
Add tests for IPython.lib.latextools
r7858 \usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bm}
\pagestyle{empty}
\begin{document}
$$x^2$$
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 \end{document}'''
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160
Oscar Gustafsson
Better color options and added scale
r25161 @skipif_not_matplotlib
@onlyif_cmds_exist('latex', 'dvipng')
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160 def test_latex_to_png_color():
"""
Test color settings for latex_to_png.
"""
latex_string = "$x^2$"
default_value = latextools.latex_to_png(latex_string, wrap=False)
Oscar Gustafsson
Better color options and added scale
r25161 default_hexblack = latextools.latex_to_png(latex_string, wrap=False,
color='#000000')
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160 dvipng_default = latextools.latex_to_png_dvipng(latex_string, False)
dvipng_black = latextools.latex_to_png_dvipng(latex_string, False, 'Black')
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert dvipng_default == dvipng_black
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160 mpl_default = latextools.latex_to_png_mpl(latex_string, False)
mpl_black = latextools.latex_to_png_mpl(latex_string, False, 'Black')
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert mpl_default == mpl_black
assert default_value in [dvipng_black, mpl_black]
assert default_hexblack in [dvipng_black, mpl_black]
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160
# Test that dvips name colors can be used without error
Oscar Gustafsson
Better color options and added scale
r25161 dvipng_maroon = latextools.latex_to_png_dvipng(latex_string, False,
'Maroon')
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160 # And that it doesn't return the black one
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert dvipng_black != dvipng_maroon
Oscar Gustafsson
Enable changing the font color for LaTeX rendering
r25160
mpl_maroon = latextools.latex_to_png_mpl(latex_string, False, 'Maroon')
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert mpl_black != mpl_maroon
Oscar Gustafsson
Better color options and added scale
r25161 mpl_white = latextools.latex_to_png_mpl(latex_string, False, 'White')
mpl_hexwhite = latextools.latex_to_png_mpl(latex_string, False, '#FFFFFF')
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert mpl_white == mpl_hexwhite
Oscar Gustafsson
Better color options and added scale
r25161
mpl_white_scale = latextools.latex_to_png_mpl(latex_string, False,
'White', 1.2)
Matthias Bussonnier
Migrate some tests to pytest only, and start removing yield-tests.
r25800 assert mpl_white != mpl_white_scale
Oscar Gustafsson
Better color options and added scale
r25161
def test_latex_to_png_invalid_hex_colors():
"""
Test that invalid hex colors provided to dvipng gives an exception.
"""
latex_string = "$x^2$"
Samuel Gaist
[lib][tests][latextools] Remove nose
r26914 pytest.raises(
ValueError,
lambda: latextools.latex_to_png(
latex_string, backend="dvipng", color="#f00bar"
),
)
pytest.raises(
ValueError,
lambda: latextools.latex_to_png(latex_string, backend="dvipng", color="#f00"),
)