aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_compile_markdown.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:50 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:50 -0500
commit475d074fd74425efbe783fad08f97f2df0c4909f (patch)
tree2acdae53999b3c74b716efa4edb5b40311fa356a /tests/test_compile_markdown.py
parentcd502d52787f666fff3254d7d7e7578930c813c2 (diff)
parent3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (diff)
Update upstream source from tag 'upstream/8.1.2'
Update to upstream version '8.1.2' with Debian dir e5e966a9e6010ef70618dc9a61558fa4db35aceb
Diffstat (limited to 'tests/test_compile_markdown.py')
-rw-r--r--tests/test_compile_markdown.py116
1 files changed, 61 insertions, 55 deletions
diff --git a/tests/test_compile_markdown.py b/tests/test_compile_markdown.py
index 99f44fd..88ac290 100644
--- a/tests/test_compile_markdown.py
+++ b/tests/test_compile_markdown.py
@@ -1,72 +1,78 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-import os
-import sys
-
-
import io
-import shutil
-import tempfile
-import unittest
from os import path
-from nikola.plugins.compile.markdown import CompileMarkdown
-from .base import BaseTestCase, FakeSite
+import pytest
+from nikola.plugins.compile.markdown import CompileMarkdown
-class CompileMarkdownTests(BaseTestCase):
- 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')
+from .helper import FakeSite
+
+
+@pytest.mark.parametrize(
+ "input_str, expected_output",
+ [
+ pytest.param("", "", id="empty"),
+ pytest.param(
+ "[podcast]https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]",
+ '<p><audio controls=""><source src="https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3" type="audio/mpeg"></source></audio></p>',
+ id="mdx podcast",
+ ),
+ pytest.param(
+ "~~striked out text~~",
+ "<p><del>striked out text</del></p>",
+ id="strikethrough",
+ ),
+ pytest.param(
+ """\
+ #!python
+ from this
+""",
+ """\
+<table class="codehilitetable"><tr><td class="linenos">\
+<div class="linenodiv"><pre>1</pre></div>\
+</td><td class="code"><pre class="code literal-block"><span></span>\
+<code><span class="kn">from</span> <span class="nn">this</span>
+</code></pre>
+</td></tr></table>
+""",
+ id="hilite",
+ ),
+ ],
+)
+def test_compiling_markdown(
+ compiler, input_path, output_path, input_str, expected_output
+):
+ output = markdown_compile(compiler, input_path, output_path, input_str)
+ assert output.strip() == expected_output.strip()
- self.compiler = CompileMarkdown()
- self.compiler.set_site(FakeSite())
- def compile(self, input_string):
- with io.open(self.input_path, "w+", encoding="utf8") as input_file:
- input_file.write(input_string)
+@pytest.fixture(scope="module")
+def site():
+ return FakeSite()
- self.compiler.compile_html(self.input_path, self.output_path)
- output_str = None
- with io.open(self.output_path, "r", encoding="utf8") as output_path:
- output_str = output_path.read()
+@pytest.fixture(scope="module")
+def compiler(site):
+ compiler = CompileMarkdown()
+ compiler.set_site(site)
+ return compiler
- return output_str
- def tearDown(self):
- shutil.rmtree(self.tmp_dir)
+@pytest.fixture
+def input_path(tmpdir):
+ return path.join(str(tmpdir), "input.markdown")
- def test_compile_html_empty(self):
- input_str = ''
- actual_output = self.compile(input_str)
- self.assertEquals(actual_output, '')
- def test_compile_html_code_hilite(self):
- input_str = '''\
- #!python
- from this
-'''
- expected_output = '''\
-<table class="codehilitetable"><tr><td class="linenos">\
-<div class="linenodiv"><pre>1</pre></div>\
-</td><td class="code"><pre class="code literal-block"><span></span>\
-<span class="kn">from</span> <span class="nn">this</span>
-</pre>
-</td></tr></table>
-'''
+@pytest.fixture
+def output_path(tmpdir):
+ return path.join(str(tmpdir), "output.html")
- actual_output = self.compile(input_str)
- self.assertEquals(actual_output.strip(), expected_output.strip())
- def test_compile_strikethrough(self):
- input_str = '~~striked out text~~'
- expected_output = '<p><del>striked out text</del></p>'
+def markdown_compile(compiler, input_path, output_path, text):
+ with io.open(input_path, "w+", encoding="utf8") as input_file:
+ input_file.write(text)
- actual_output = self.compile(input_str)
- self.assertEquals(actual_output.strip(), expected_output.strip())
+ compiler.compile(input_path, output_path, lang="en")
-if __name__ == '__main__':
- unittest.main()
+ with io.open(output_path, "r", encoding="utf8") as output_path:
+ return output_path.read()