From 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Wed, 3 Feb 2021 19:17:00 -0500 Subject: New upstream version 8.1.2. --- tests/test_compile_markdown.py | 158 +++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 94 deletions(-) (limited to 'tests/test_compile_markdown.py') 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]", + '

', + id="mdx podcast", + ), + pytest.param( + "~~striked out text~~", + "

striked out text

", + id="strikethrough", + ), + pytest.param( + """\ + #!python + from this +""", + """\ +
\ +
1
\ +
\
+from this
+
+
+""", + 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 = '''\ -
\ -
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() + +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() -- cgit v1.2.3