##// END OF EJS Templates
Add new filter tests
Jonathan Frederic -
Show More
@@ -0,0 +1,72 b''
1 """
2 Module with tests for Latex
3 """
4
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17
18 from ...tests.base import TestsBase
19 from ..latex import *
20
21
22 #-----------------------------------------------------------------------------
23 # Class
24 #-----------------------------------------------------------------------------
25
26 class TestLatex(TestsBase):
27
28
29 def test_escape_latex(self):
30 """
31 escape_latex test
32 """
33 tests = [
34 (r'How are \you doing today?', r'How are \textbackslashyou doing today?'),
35 (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslashescapechar=`\textbackslashA\textbackslashcatcode`\textbackslash|=0 |string|foo'),
36 (r'# $ % & ~ _ ^ \ { }',r'\# \$ \% \& \~{} \_ \^{} \textbackslash \{ \}'),
37 ('','')]
38
39 for test in tests:
40 yield self._try_escape_latex, test[0], test[1]
41
42
43 def _try_escape_latex(self, test, result):
44 """
45 Try to remove latex from string
46 """
47 assert escape_latex(test) == result
48
49
50 def test_strip_math_space(self):
51 """
52 strip_math_space test
53 """
54 tests = [
55 ('$e$','$e$'),
56 ('$ e $','$e$'),
57 ('xxx$e^i$yyy','xxx$e^i$yyy'),
58 ('xxx$ e^i $yyy','xxx$e^i$yyy'),
59 ('xxx$e^i $yyy','xxx$e^i$yyy'),
60 ('xxx$ e^i$yyy','xxx$e^i$yyy'),
61 ('\$ e $ e $','\$ e $e$'),
62 ('','')]
63
64 for test in tests:
65 yield self._try_strip_math_space, test[0], test[1]
66
67
68 def _try_strip_math_space(self, test, result):
69 """
70 Try to remove spaces between dollar symbols and contents correctly
71 """
72 assert strip_math_space(test) == result
@@ -0,0 +1,315 b''
1
2 """
3 Module with tests for Markdown
4 """
5
6 #-----------------------------------------------------------------------------
7 # Copyright (c) 2013, the IPython Development Team.
8 #
9 # Distributed under the terms of the Modified BSD License.
10 #
11 # The full license is in the file COPYING.txt, distributed with this software.
12 #-----------------------------------------------------------------------------
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17
18
19 from IPython.testing.decorators import onlyif_cmds_exist
20 # @onlyif_cmds_exist('pandoc')
21
22 from ...tests.base import TestsBase
23 from ..markdown import *
24
25
26 #-----------------------------------------------------------------------------
27 # Class
28 #-----------------------------------------------------------------------------
29
30 class TestMarkdown(TestsBase):
31
32 tests = [
33 '*test',
34 '**test',
35 '*test*',
36 '_test_',
37 '__test__',
38 '__*test*__',
39 '**test**',
40 '#test',
41 '##test',
42 'test\n----',
43 'test [link](https://google.com/)',
44 """
45 List
46 ----
47 - Test
48 - Test
49 1. Test
50 2. Test
51 - Test
52 - Test
53 2. Test
54 """,
55 "test\ntest",
56 "test\n test",
57 "test\n\n---\n\ntest",
58 "test\n\n***\n\ntest",
59 """
60 #Code
61
62 Below
63
64 def hello_world(self):
65 print('hello_world')
66
67 """,
68 """
69 Quote
70 -----
71
72 Mike said
73
74 > You are so cool!
75 > I wish I could do that.
76 """,
77 "inline `quote`"]
78
79
80 @onlyif_cmds_exist('pandoc')
81 def test_markdown2latex(self):
82 """
83 markdown2latex test
84 """
85 results = [
86 '*test',
87 '**test',
88 r'\emph{test}',
89 r'\emph{test}',
90 r'\textbf{test}',
91 r'\textbf{\emph{test}}',
92 r'\textbf{test}',
93 r'\section{test}',
94 r'\subsection{test}',
95 r'\subsection{test}',
96 r'test \href{https://google.com/}{link}',
97 r"""
98 \subsection{List}
99
100 \begin{itemize}
101 \item
102 Test
103 \item
104 Test
105
106 \begin{enumerate}[1.]
107 \item
108 Test
109 \item
110 Test
111
112 \begin{itemize}
113 \item
114 Test
115 \item
116 Test
117 \end{itemize}
118 \item
119 Test
120 \end{enumerate}
121 \end{itemize}
122 """,
123 'test test',
124 'test test',
125 r"""
126 test
127
128 \begin{center}\rule{3in}{0.4pt}\end{center}
129
130 test
131 """,
132 r"""
133 test
134
135 \begin{center}\rule{3in}{0.4pt}\end{center}
136
137 test
138 """,
139 r"""
140 \section{Code}
141
142 Below
143
144 \begin{verbatim}
145 def hello_world(self):
146 print('hello_world')
147 \end{verbatim}
148
149 """,
150 r"""
151 \subsection{Quote}
152
153 Mike said
154
155 \begin{quote}
156 You are so cool! I wish I could do that.
157 \end{quote}
158 """,
159 r'inline \texttt{quote}']
160 for index, test in enumerate(self.tests):
161 yield self._try_markdown2latex, test, results[index]
162
163
164 def _try_markdown2latex(self, test, results):
165 assert self.fuzzy_compare(markdown2latex(test), results)
166
167
168 @onlyif_cmds_exist('pandoc')
169 def test_markdown2html(self):
170 """
171 markdown2html test
172 """
173 results = [
174 '<p>*test</p>',
175 '<p>**test</p>',
176 '<p><em>test</em></p>',
177 '<p><em>test</em></p>',
178 '<p><strong>test</strong></p>',
179 '<p><strong><em>test</em></strong></p>',
180 '<p><strong>test</strong></p>',
181 '<h1 id="test">test</h1>',
182 '<h2 id="test">test</h2>',
183 '<h2 id="test">test</h2>',
184 '<p>test <a href="https://google.com/">link</a></p>',
185 """
186 <h2 id="list">List</h2>
187 <ul>
188 <li>Test</li>
189 <li>Test
190 <ol style="list-style-type: decimal">
191 <li>Test</li>
192 <li>Test
193 <ul>
194 <li>Test</li>
195 <li>Test</li>
196 </ul></li>
197 <li>Test</li>
198 </ol></li>
199 </ul>
200
201 """,
202 '<p>test test</p>',
203 '<p>test test</p>',
204 """
205 <p>test</p>
206 <hr />
207 <p>test</p>
208 """,
209 """
210 <p>test</p>
211 <hr />
212 <p>test</p>
213 """,
214 """
215 <h1 id="code">Code</h1>
216 <p>Below</p>
217 <pre><code>def hello_world(self):
218 print(&#39;hello_world&#39;)</code></pre>
219
220 """,
221 """
222 <h2 id="quote">Quote</h2>
223 <p>Mike said</p>
224 <blockquote>
225 <p>You are so cool! I wish I could do that.</p>
226 </blockquote>
227
228 """,
229 '<p>inline <code>quote</code></p>']
230 for index, test in enumerate(self.tests):
231 yield self._try_markdown2html, test, results[index]
232
233
234 def _try_markdown2html(self, test, results):
235 assert self.fuzzy_compare(markdown2html(test), results)
236
237
238 @onlyif_cmds_exist('pandoc')
239 def test_markdown2rst(self):
240 """
241 markdown2rst test
242 """
243 results = [
244 '\*test',
245 '\*\*test',
246 '*test*',
247 '*test*',
248 '**test**',
249 '***test***',
250 '**test**',
251 'test\n====',
252 'test\n----',
253 'test\n----',
254 'test `link <https://google.com/>`_',
255 """
256 List
257 ----
258
259 - Test
260 - Test
261
262 1. Test
263 2. Test
264
265 - Test
266 - Test
267
268 3. Test
269
270 """,
271 'test test',
272 'test test',
273 """
274 test
275
276 --------------
277
278 test
279 """,
280 """
281 test
282
283 --------------
284
285 test
286
287 """,
288 """
289 Code
290 ====
291
292 Below
293
294 ::
295
296 def hello_world(self):
297 print('hello_world')
298
299 """,
300 """
301 Quote
302 -----
303
304 Mike said
305
306 You are so cool! I wish I could do that.
307
308 """,
309 'inline ``quote``']
310 for index, test in enumerate(self.tests):
311 yield self._try_markdown2rst, test, results[index]
312
313
314 def _try_markdown2rst(self, test, results):
315 assert self.fuzzy_compare(markdown2rst(test), results)
@@ -0,0 +1,126 b''
1 """
2 Module with tests for Strings
3 """
4
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17
18 from ...tests.base import TestsBase
19 from ..strings import *
20
21
22 #-----------------------------------------------------------------------------
23 # Class
24 #-----------------------------------------------------------------------------
25
26 class TestStrings(TestsBase):
27
28 def test_wrap_text(self):
29 """
30 wrap_text test
31 """
32 test_text = """
33 Tush! never tell me; I take it much unkindly
34 That thou, Iago, who hast had my purse
35 As if the strings were thine, shouldst know of this.
36 """
37 for length in [30,5,1]:
38 yield self._confirm_wrap_text, test_text, length
39
40 def _confirm_wrap_text(self, text, length):
41 for line in wrap_text(text, length).split('\n'):
42 assert len(line) <= length
43
44 def test_html2text(self):
45 """
46 html2text test
47 """
48 #TODO: More tests
49 assert html2text('<name>joe</name>') == 'joe'
50
51
52 def test_add_anchor(self):
53 """
54 add_anchor test
55 """
56 #TODO: More tests
57 assert add_anchor('<b>Hello World!</b>') == '<b id="Hello-World!">Hello World!<a class="anchor-link" href="#Hello-World!">&#182;</a></b>'
58
59
60 def test_strip_dollars(self):
61 """
62 strip_dollars test
63 """
64 tests = [
65 ('', ''),
66 ('$$', ''),
67 ('$H$', 'H'),
68 ('$He', 'He'),
69 ('H$el', 'H$el'),
70 ('Hell$', 'Hell'),
71 ('Hello', 'Hello'),
72 ('W$o$rld', 'W$o$rld')]
73 for test in tests:
74 yield self._try_strip_dollars, test[0], test[1]
75
76
77 def _try_strip_dollars(self, test, result):
78 assert strip_dollars(test) == result
79
80
81 def test_strip_files_prefix(self):
82 """
83 strip_files_prefix test
84 """
85 tests = [
86 ('', ''),
87 ('/files', '/files'),
88 ('test="/files"', 'test="/files"'),
89 ('My files are in `files/`', 'My files are in `files/`'),
90 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')]
91 for test in tests:
92 yield self._try_files_prefix, test[0], test[1]
93
94
95 def _try_files_prefix(self, test, result):
96 assert strip_files_prefix(test) == result
97
98
99 def test_comment_lines(self):
100 """
101 comment_lines test
102 """
103 for line in comment_lines('hello\nworld\n!').split('\n'):
104 assert line.startswith('# ')
105 for line in comment_lines('hello\nworld\n!', 'beep').split('\n'):
106 assert line.startswith('beep')
107
108
109 def test_get_lines(self):
110 """
111 get_lines test
112 """
113 text = "hello\nworld\n!"
114 assert get_lines(text, start=1) == "world\n!"
115 assert get_lines(text, end=2) == "hello\nworld"
116 assert get_lines(text, start=2, end=5) == "!"
117 assert get_lines(text, start=-2) == "world\n!"
118
119
120 def test_ipython2python(self):
121 """
122 ipython2python test
123 """
124 #TODO: More tests
125 results = ipython2python('%%pylab\nprint("Hello-World")')
126 assert self.fuzzy_compare(results, "get_ipython().run_cell_magic(u'pylab', u'', u'print(\"Hello-World\")')")
General Comments 0
You need to be logged in to leave comments. Login now