test_markdown.py
93 lines
| 2.5 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r11902 | |||
""" | ||||
Module with tests for Markdown | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r11920 | from copy import copy | ||
Jonathan Frederic
|
r11902 | |||
Jonathan Frederic
|
r11917 | from IPython.utils.py3compat import string_types | ||
Jonathan Frederic
|
r11935 | from IPython.testing import decorators as dec | ||
Jonathan Frederic
|
r11902 | |||
from ...tests.base import TestsBase | ||||
Jonathan Frederic
|
r11928 | from ..markdown import markdown2latex, markdown2html, markdown2rst | ||
Jonathan Frederic
|
r11902 | |||
#----------------------------------------------------------------------------- | ||||
# Class | ||||
#----------------------------------------------------------------------------- | ||||
class TestMarkdown(TestsBase): | ||||
tests = [ | ||||
'*test', | ||||
'**test', | ||||
'*test*', | ||||
'_test_', | ||||
'__test__', | ||||
'__*test*__', | ||||
'**test**', | ||||
'#test', | ||||
'##test', | ||||
'test\n----', | ||||
Jonathan Frederic
|
r11916 | 'test [link](https://google.com/)'] | ||
Jonathan Frederic
|
r11902 | |||
Jonathan Frederic
|
r11917 | tokens = [ | ||
'*test', | ||||
'**test', | ||||
'test', | ||||
'test', | ||||
'test', | ||||
'test', | ||||
'test', | ||||
'test', | ||||
'test', | ||||
'test', | ||||
('test', 'https://google.com/')] | ||||
Jonathan Frederic
|
r11902 | |||
Jonathan Frederic
|
r11935 | @dec.onlyif_cmds_exist('pandoc') | ||
Jonathan Frederic
|
r11902 | def test_markdown2latex(self): | ||
Jonathan Frederic
|
r11934 | """markdown2latex test""" | ||
Jonathan Frederic
|
r11902 | for index, test in enumerate(self.tests): | ||
Thomas Kluyver
|
r12373 | self._try_markdown(markdown2latex, test, self.tokens[index]) | ||
Jonathan Frederic
|
r11902 | |||
Jonathan Frederic
|
r11935 | @dec.onlyif_cmds_exist('pandoc') | ||
Jonathan Frederic
|
r11902 | def test_markdown2html(self): | ||
Jonathan Frederic
|
r11934 | """markdown2html test""" | ||
Jonathan Frederic
|
r11902 | for index, test in enumerate(self.tests): | ||
Thomas Kluyver
|
r12373 | self._try_markdown(markdown2html, test, self.tokens[index]) | ||
Jonathan Frederic
|
r11902 | |||
Jonathan Frederic
|
r11935 | @dec.onlyif_cmds_exist('pandoc') | ||
Jonathan Frederic
|
r11902 | def test_markdown2rst(self): | ||
Jonathan Frederic
|
r11934 | """markdown2rst test""" | ||
Jonathan Frederic
|
r11920 | |||
#Modify token array for rst, escape asterik | ||||
tokens = copy(self.tokens) | ||||
tokens[0] = r'\*test' | ||||
tokens[1] = r'\*\*test' | ||||
Jonathan Frederic
|
r11902 | for index, test in enumerate(self.tests): | ||
Thomas Kluyver
|
r12373 | self._try_markdown(markdown2rst, test, tokens[index]) | ||
Jonathan Frederic
|
r11902 | |||
Jonathan Frederic
|
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 | ||||