Show More
@@ -1,139 +1,139 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """Tests for IPython.utils.path.py""" |
|
3 | 3 | |
|
4 | 4 | #----------------------------------------------------------------------------- |
|
5 | 5 | # Copyright (C) 2008-2011 The IPython Development Team |
|
6 | 6 | # |
|
7 | 7 | # Distributed under the terms of the BSD License. The full license is in |
|
8 | 8 | # the file COPYING, distributed as part of this software. |
|
9 | 9 | #----------------------------------------------------------------------------- |
|
10 | 10 | |
|
11 | 11 | import nose.tools as nt |
|
12 | 12 | |
|
13 | 13 | from IPython.lib import latextools |
|
14 | 14 | from IPython.testing.decorators import onlyif_cmds_exist, skipif_not_matplotlib |
|
15 | 15 | from IPython.testing.tools import monkeypatch |
|
16 | 16 | from IPython.utils.process import FindCmdError |
|
17 | 17 | |
|
18 | 18 | |
|
19 | 19 | def test_latex_to_png_dvipng_fails_when_no_cmd(): |
|
20 | 20 | """ |
|
21 | 21 | `latex_to_png_dvipng` should return None when there is no required command |
|
22 | 22 | """ |
|
23 | 23 | for command in ['latex', 'dvipng']: |
|
24 | 24 | yield (check_latex_to_png_dvipng_fails_when_no_cmd, command) |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | def check_latex_to_png_dvipng_fails_when_no_cmd(command): |
|
28 | 28 | def mock_find_cmd(arg): |
|
29 | 29 | if arg == command: |
|
30 | 30 | raise FindCmdError |
|
31 | 31 | |
|
32 | 32 | with monkeypatch(latextools, "find_cmd", mock_find_cmd): |
|
33 | 33 | nt.assert_equals(latextools.latex_to_png_dvipng("whatever", True), |
|
34 | 34 | None) |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | @onlyif_cmds_exist('latex', 'dvipng') |
|
38 | 38 | def test_latex_to_png_dvipng_runs(): |
|
39 | 39 | """ |
|
40 | 40 | Test that latex_to_png_dvipng just runs without error. |
|
41 | 41 | """ |
|
42 | 42 | def mock_kpsewhich(filename): |
|
43 | 43 | nt.assert_equals(filename, "breqn.sty") |
|
44 | 44 | return None |
|
45 | 45 | |
|
46 | for (s, wrap) in [("$$x^2$$", False), ("x^2", True)]: | |
|
46 | for (s, wrap) in [(u"$$x^2$$", False), (u"x^2", True)]: | |
|
47 | 47 | yield (latextools.latex_to_png_dvipng, s, wrap) |
|
48 | 48 | |
|
49 | 49 | with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): |
|
50 | 50 | yield (latextools.latex_to_png_dvipng, s, wrap) |
|
51 | 51 | |
|
52 | 52 | @skipif_not_matplotlib |
|
53 | 53 | def test_latex_to_png_mpl_runs(): |
|
54 | 54 | """ |
|
55 | 55 | Test that latex_to_png_mpl just runs without error. |
|
56 | 56 | """ |
|
57 | 57 | def mock_kpsewhich(filename): |
|
58 | 58 | nt.assert_equals(filename, "breqn.sty") |
|
59 | 59 | return None |
|
60 | 60 | |
|
61 | 61 | for (s, wrap) in [("$x^2$", False), ("x^2", True)]: |
|
62 | 62 | yield (latextools.latex_to_png_mpl, s, wrap) |
|
63 | 63 | |
|
64 | 64 | with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): |
|
65 | 65 | yield (latextools.latex_to_png_mpl, s, wrap) |
|
66 | 66 | |
|
67 | 67 | @skipif_not_matplotlib |
|
68 | 68 | def test_latex_to_html(): |
|
69 | 69 | img = latextools.latex_to_html("$x^2$") |
|
70 | 70 | nt.assert_in("data:image/png;base64,iVBOR", img) |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | def test_genelatex_no_wrap(): |
|
74 | 74 | """ |
|
75 | 75 | Test genelatex with wrap=False. |
|
76 | 76 | """ |
|
77 | 77 | def mock_kpsewhich(filename): |
|
78 | 78 | assert False, ("kpsewhich should not be called " |
|
79 | 79 | "(called with {0})".format(filename)) |
|
80 | 80 | |
|
81 | 81 | with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): |
|
82 | 82 | nt.assert_equals( |
|
83 | 83 | '\n'.join(latextools.genelatex("body text", False)), |
|
84 | 84 | r'''\documentclass{article} |
|
85 | 85 | \usepackage{amsmath} |
|
86 | 86 | \usepackage{amsthm} |
|
87 | 87 | \usepackage{amssymb} |
|
88 | 88 | \usepackage{bm} |
|
89 | 89 | \pagestyle{empty} |
|
90 | 90 | \begin{document} |
|
91 | 91 | body text |
|
92 | 92 | \end{document}''') |
|
93 | 93 | |
|
94 | 94 | |
|
95 | 95 | def test_genelatex_wrap_with_breqn(): |
|
96 | 96 | """ |
|
97 | 97 | Test genelatex with wrap=True for the case breqn.sty is installed. |
|
98 | 98 | """ |
|
99 | 99 | def mock_kpsewhich(filename): |
|
100 | 100 | nt.assert_equals(filename, "breqn.sty") |
|
101 | 101 | return "path/to/breqn.sty" |
|
102 | 102 | |
|
103 | 103 | with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): |
|
104 | 104 | nt.assert_equals( |
|
105 | 105 | '\n'.join(latextools.genelatex("x^2", True)), |
|
106 | 106 | r'''\documentclass{article} |
|
107 | 107 | \usepackage{amsmath} |
|
108 | 108 | \usepackage{amsthm} |
|
109 | 109 | \usepackage{amssymb} |
|
110 | 110 | \usepackage{bm} |
|
111 | 111 | \usepackage{breqn} |
|
112 | 112 | \pagestyle{empty} |
|
113 | 113 | \begin{document} |
|
114 | 114 | \begin{dmath*} |
|
115 | 115 | x^2 |
|
116 | 116 | \end{dmath*} |
|
117 | 117 | \end{document}''') |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | def test_genelatex_wrap_without_breqn(): |
|
121 | 121 | """ |
|
122 | 122 | Test genelatex with wrap=True for the case breqn.sty is not installed. |
|
123 | 123 | """ |
|
124 | 124 | def mock_kpsewhich(filename): |
|
125 | 125 | nt.assert_equals(filename, "breqn.sty") |
|
126 | 126 | return None |
|
127 | 127 | |
|
128 | 128 | with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): |
|
129 | 129 | nt.assert_equals( |
|
130 | 130 | '\n'.join(latextools.genelatex("x^2", True)), |
|
131 | 131 | r'''\documentclass{article} |
|
132 | 132 | \usepackage{amsmath} |
|
133 | 133 | \usepackage{amsthm} |
|
134 | 134 | \usepackage{amssymb} |
|
135 | 135 | \usepackage{bm} |
|
136 | 136 | \pagestyle{empty} |
|
137 | 137 | \begin{document} |
|
138 | 138 | $$x^2$$ |
|
139 | 139 | \end{document}''') |
General Comments 0
You need to be logged in to leave comments.
Login now