##// END OF EJS Templates
Fix typo in deprecated class name.
Fix typo in deprecated class name.

File last commit:

r17259:90f2049a
r17687:2fcc6d49
Show More
test_markdown.py
88 lines | 2.4 KiB | text/x-python | PythonLexer
Thomas Kluyver
Fix mathjax pass-through with mistune
r17259 """Tests for conversions from markdown to other formats"""
Jonathan Frederic
Add new filter tests
r11902
Thomas Kluyver
Fix mathjax pass-through with mistune
r17259 # Copyright (c) IPython Development Team.
Jonathan Frederic
Add new filter tests
r11902 # Distributed under the terms of the Modified BSD License.
Jonathan Frederic
Escape asterik in rst tests
r11920 from copy import copy
Jonathan Frederic
Add new filter tests
r11902
Jonathan Frederic
Check for tokens instead of fuzzy output comparison
r11917 from IPython.utils.py3compat import string_types
Jonathan Frederic
Use decorator to enable test generation
r11935 from IPython.testing import decorators as dec
Jonathan Frederic
Add new filter tests
r11902
from ...tests.base import TestsBase
Jonathan Frederic
Explicit imports
r11928 from ..markdown import markdown2latex, markdown2html, markdown2rst
Jonathan Frederic
Add new filter tests
r11902
class TestMarkdown(TestsBase):
tests = [
'*test',
'**test',
'*test*',
'_test_',
'__test__',
'__*test*__',
'**test**',
'#test',
'##test',
'test\n----',
Jonathan Frederic
Removed large tests
r11916 'test [link](https://google.com/)']
Jonathan Frederic
Add new filter tests
r11902
Jonathan Frederic
Check for tokens instead of fuzzy output comparison
r11917 tokens = [
'*test',
'**test',
'test',
'test',
'test',
'test',
'test',
'test',
'test',
'test',
('test', 'https://google.com/')]
Jonathan Frederic
Add new filter tests
r11902
Jonathan Frederic
Use decorator to enable test generation
r11935 @dec.onlyif_cmds_exist('pandoc')
Jonathan Frederic
Add new filter tests
r11902 def test_markdown2latex(self):
Jonathan Frederic
Shrink header comments
r11934 """markdown2latex test"""
Jonathan Frederic
Add new filter tests
r11902 for index, test in enumerate(self.tests):
Thomas Kluyver
Remove ParametricTestCase from nbconvert tests
r12373 self._try_markdown(markdown2latex, test, self.tokens[index])
Jonathan Frederic
Add new filter tests
r11902
def test_markdown2html(self):
Jonathan Frederic
Shrink header comments
r11934 """markdown2html test"""
Jonathan Frederic
Add new filter tests
r11902 for index, test in enumerate(self.tests):
Thomas Kluyver
Remove ParametricTestCase from nbconvert tests
r12373 self._try_markdown(markdown2html, test, self.tokens[index])
Jonathan Frederic
Add new filter tests
r11902
Thomas Kluyver
Fix mathjax pass-through with mistune
r17259 def test_markdown2html_math(self):
# Mathematical expressions should be passed through unaltered
cases = [("\\begin{equation*}\n"
"\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n"
"\\end{equation*}"),
("$$\n"
"a = 1 *3* 5\n"
"$$"),
"$ a = 1 *3* 5 $",
]
for case in cases:
self.assertIn(case, markdown2html(case))
Jonathan Frederic
Add new filter tests
r11902
Jonathan Frederic
Use decorator to enable test generation
r11935 @dec.onlyif_cmds_exist('pandoc')
Jonathan Frederic
Add new filter tests
r11902 def test_markdown2rst(self):
Jonathan Frederic
Shrink header comments
r11934 """markdown2rst test"""
Jonathan Frederic
Escape asterik in rst tests
r11920
#Modify token array for rst, escape asterik
tokens = copy(self.tokens)
tokens[0] = r'\*test'
tokens[1] = r'\*\*test'
Jonathan Frederic
Add new filter tests
r11902 for index, test in enumerate(self.tests):
Thomas Kluyver
Remove ParametricTestCase from nbconvert tests
r12373 self._try_markdown(markdown2rst, test, tokens[index])
Jonathan Frederic
Add new filter tests
r11902
Jonathan Frederic
Check for tokens instead of fuzzy output comparison
r11917 def _try_markdown(self, method, test, tokens):
results = method(test)
if isinstance(tokens, string_types):
assert tokens in results
else:
for token in tokens:
assert token in results