From 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 Mon Sep 17 00:00:00 2001
From: Unit 193 Here's a gist file inline:
-striked out text
+""",
+ 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 = '''\
-\
- 1
\
-from this
-
-
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