From 0c4dfdec5b55b6064dccc38bbfb0a7c0699c895a Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Thu, 30 May 2013 17:41:06 -0300 Subject: Imported Upstream version 5.4.4 --- tests/test_compile_markdown.py | 122 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 tests/test_compile_markdown.py (limited to 'tests/test_compile_markdown.py') diff --git a/tests/test_compile_markdown.py b/tests/test_compile_markdown.py new file mode 100644 index 0000000..a1f8591 --- /dev/null +++ b/tests/test_compile_markdown.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +import codecs +import shutil +import tempfile +import unittest +from os import path + +from nikola.plugins.compile_markdown import CompileMarkdown + + +class CompileMarkdownTests(unittest.TestCase): + def setUp(self): + self.tmp_dir = tempfile.mkdtemp() + self.input_path = path.join(self.tmp_dir, 'input.markdown') + self.output_path = path.join(self.tmp_dir, 'output.html') + + self.compiler = CompileMarkdown() + + def compile(self, input_string): + with codecs.open(self.input_path, "w+", "utf8") as input_file: + input_file.write(input_string) + + self.compiler.compile_html(self.input_path, self.output_path) + + output_str = None + with codecs.open(self.output_path, "r", "utf8") as output_path: + output_str = output_path.read() + + return output_str + + def tearDown(self): + shutil.rmtree(self.tmp_dir) + + def test_compile_html_empty(self): + input_str = '' + actual_output = self.compile(input_str) + self.assertEquals(actual_output, '') + + def test_compile_html_heading_tags(self): + input_str = '''\ +# header 1 +## header 2 +### header 3 +#### header 4 +##### header 5 +###### header 6 +''' + expected_output = '''\ +

header 1

+

header 2

+

header 3

+
header 4
+
header 5
+header 6 +''' + + actual_output = self.compile(input_str) + self.assertEquals(actual_output.strip(), expected_output.strip()) + + def test_compile_html_code_hilite(self): + input_str = '''\ + #!python + from this +''' + expected_output = '''\ +
\ +
1
\ +
\ +
from this
+
+
+''' + + actual_output = self.compile(input_str) + self.assertEquals(actual_output.strip(), expected_output.strip()) + + def test_compile_html_gist(self): + input_str = '''\ +Here's a gist file inline: +[:gist: 4747847 zen.py] + +Cool, eh? +''' + expected_output = '''\ +

Here's a gist file inline: +

+ + +
+

+

Cool, eh?

+''' + actual_output = self.compile(input_str) + self.assertEquals(actual_output.strip(), expected_output.strip()) + + def test_compile_html_gist_2(self): + input_str = '''\ +Here's a gist file inline, using reStructuredText syntax: +..gist:: 4747847 zen.py + +Cool, eh? +''' + expected_output = '''\ +

Here's a gist file inline, using reStructuredText syntax: +

+ + +
+

+

Cool, eh?

+''' + actual_output = self.compile(input_str) + self.assertEquals(actual_output.strip(), expected_output.strip()) + + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3