aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_compile_markdown.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:00 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:00 -0500
commit3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (patch)
treea7cf56282e54f05785243bc1e903d6594f2c06ba /tests/test_compile_markdown.py
parent787b97a4cb24330b36f11297c6d3a7a473a907d0 (diff)
New upstream version 8.1.2.upstream/8.1.2
Diffstat (limited to 'tests/test_compile_markdown.py')
-rw-r--r--tests/test_compile_markdown.py158
1 files changed, 64 insertions, 94 deletions
diff --git a/tests/test_compile_markdown.py b/tests/test_compile_markdown.py
index 47cbdbb..88ac290 100644
--- a/tests/test_compile_markdown.py
+++ b/tests/test_compile_markdown.py
@@ -1,108 +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
+import pytest
+
from nikola.plugins.compile.markdown import CompileMarkdown
-from .base import BaseTestCase, FakeSite
+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()
-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')
- self.compiler = CompileMarkdown()
- self.compiler.set_site(FakeSite())
+@pytest.fixture(scope="module")
+def site():
+ return FakeSite()
- def compile(self, input_string):
- with io.open(self.input_path, "w+", encoding="utf8") as input_file:
- input_file.write(input_string)
- self.compiler.compile_html(self.input_path, self.output_path)
+@pytest.fixture(scope="module")
+def compiler(site):
+ compiler = CompileMarkdown()
+ compiler.set_site(site)
+ return compiler
- output_str = None
- with io.open(self.output_path, "r", encoding="utf8") as output_path:
- output_str = output_path.read()
- return output_str
+@pytest.fixture
+def input_path(tmpdir):
+ return path.join(str(tmpdir), "input.markdown")
- 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, '')
+@pytest.fixture
+def output_path(tmpdir):
+ return path.join(str(tmpdir), "output.html")
- 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 class="kn">from</span> <span class="nn">this</span>
-</pre>
-</td></tr></table>
-'''
-
- 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 = '''\
-<p>Here's a gist file inline:
-<div class="gist">
-<script src="https://gist.github.com/4747847.js?file=zen.py"></script>
-<noscript>
-<pre>import this</pre>
-</noscript>
-</div>
-</p>
-<p>Cool, eh?</p>
-'''
- 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 = '''\
-<p>Here's a gist file inline, using reStructuredText syntax:
-<div class="gist">
-<script src="https://gist.github.com/4747847.js?file=zen.py"></script>
-<noscript>
-<pre>import this</pre>
-</noscript>
-</div>
-</p>
-<p>Cool, eh?</p>
-'''
- actual_output = self.compile(input_str)
- self.assertEquals(actual_output.strip(), expected_output.strip())
-
-
-if __name__ == '__main__':
- unittest.main()
+
+def markdown_compile(compiler, input_path, output_path, text):
+ with io.open(input_path, "w+", encoding="utf8") as input_file:
+ input_file.write(text)
+
+ compiler.compile(input_path, output_path, lang="en")
+
+ with io.open(output_path, "r", encoding="utf8") as output_path:
+ return output_path.read()