This is a simple template
" + + +def test_double_include(markdown_include): + source = "{!resources/simple.md!} and {!resources/simple_2.md!}" + html = markdown.markdown(source, extensions=[markdown_include]) + + assert ( + html == "This is a simple template and This is another simple template
" + ) + + +def test_headers(markdown_include): + source = ( + "Source file\n" + "# Heading Level 1 of main file\n" + "{!resources/header.md!}\n" + "## Heading Level 2 of main file\n" + "{!resources/header.md!}" + ) + + html = markdown.markdown(source, extensions=[markdown_include]) + + assert html == dedent( + """\ +Source file
+More included file content. + End of included content.
+More included file content. + End of included content.
""" + ) + + +def test_embedded_template(markdown_include): + source = "{!resources/template_inside.md!}" + html = markdown.markdown(source, extensions=[markdown_include]) + + assert ( + html + == "This is a simple template
\nThis is a template with a template.
" + ) + + +def test_single_include_inherit_heading_depth(markdown_include_inherit_heading_depth): + source = "{!resources/simple.md!}" + html = markdown.markdown( + source, extensions=[markdown_include_inherit_heading_depth] + ) + + assert html == "This is a simple template
" + + +def test_double_include_inherit_heading_depth(markdown_include_inherit_heading_depth): + source = "{!resources/simple.md!} and {!resources/simple_2.md!}" + html = markdown.markdown( + source, extensions=[markdown_include_inherit_heading_depth] + ) + + assert ( + html == "This is a simple template and This is another simple template
" + ) + + +def test_headers_inherit_heading_depth(markdown_include_inherit_heading_depth): + source = ( + "Source file\n" + "# Heading Level 1 of main file\n" + "{!resources/header.md!}\n" + "## Heading Level 2 of main file\n" + "{!resources/header.md!}" + ) + + html = markdown.markdown( + source, extensions=[markdown_include_inherit_heading_depth] + ) + + assert html == dedent( + """\ +Source file
+More included file content.
+End of included content.
+More included file content.
+End of included content.
""" + ) + + +def test_processor_lines(): + processor = IncludePreprocessor( + None, + { + "base_path": RESOURCE_DIR, + "encoding": "utf-8", + "inheritHeadingDepth": False, + "headingOffset": 0, + "throwException": False, + }, + ) + + source = [ + "Source file", + "# Heading Level 1 of main file", + "{!resources/header.md!}", + "## Heading Level 2 of main file", + "{!resources/header.md!}", + ] + result_lines = processor.run(source) + + assert len(result_lines) == 9 diff --git a/unittests/test_embedded.py b/unittests/test_embedded.py deleted file mode 100644 index a5e7d94..0000000 --- a/unittests/test_embedded.py +++ /dev/null @@ -1,20 +0,0 @@ -import os -from unittest import TestCase - -import markdown - -from markdown_include.include import IncludePreprocessor, MarkdownInclude - - -class TestEmbedded(TestCase): - def setUp(self) -> None: - self.maxDiff = None - self.markdown_include = MarkdownInclude( - configs={'base_path': os.path.dirname(os.path.realpath(__file__))} - ) - - def test_embedded_template(self): - source = "{!resources/template_inside.md!}" - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, "This is a simple template
\nThis is a template with a template.
") diff --git a/unittests/test_include.py b/unittests/test_include.py deleted file mode 100644 index 62bb6c7..0000000 --- a/unittests/test_include.py +++ /dev/null @@ -1,45 +0,0 @@ -import os -from unittest import TestCase - -import markdown - -from markdown_include.include import MarkdownInclude - - -class TestInclude(TestCase): - def setUp(self) -> None: - self.maxDiff = None - self.markdown_include = MarkdownInclude( - configs={'base_path': os.path.dirname(os.path.realpath(__file__))} - ) - - def test_single_include(self): - source = "{!resources/simple.md!}" - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, 'This is a simple template
') - - def test_double_include(self): - source = "{!resources/simple.md!} and {!resources/simple_2.md!}" - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, 'This is a simple template and This is another simple template
') - - def test_headers(self): - source = "Source file\n" \ - "# Heading Level 1 of main file\n" \ - "{!resources/header.md!}\n" \ - "## Heading Level 2 of main file\n" \ - "{!resources/header.md!}" - - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, "Source file
\n" - "More included file content.\n" - "End of included content.
\n" - "More included file content.\n" - "End of included content.
") diff --git a/unittests/test_include_header_indent.py b/unittests/test_include_header_indent.py deleted file mode 100644 index 35f651d..0000000 --- a/unittests/test_include_header_indent.py +++ /dev/null @@ -1,45 +0,0 @@ -import os -from unittest import TestCase - -import markdown - -from markdown_include.include import MarkdownInclude - - -class TestInclude(TestCase): - def setUp(self) -> None: - self.maxDiff = None - self.markdown_include = MarkdownInclude( - configs={'base_path': os.path.dirname(os.path.realpath(__file__)), 'inheritHeadingDepth': True} - ) - - def test_single_include(self): - source = "{!resources/simple.md!}" - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, 'This is a simple template
') - - def test_double_include(self): - source = "{!resources/simple.md!} and {!resources/simple_2.md!}" - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, 'This is a simple template and This is another simple template
') - - def test_headers(self): - source = "Source file\n" \ - "# Heading Level 1 of main file\n" \ - "{!resources/header.md!}\n" \ - "## Heading Level 2 of main file\n" \ - "{!resources/header.md!}" - - html = markdown.markdown(source, extensions=[self.markdown_include]) - - self.assertEqual(html, "Source file
\n" - "More included file content.
\n" - "End of included content.
\n" - "More included file content.
\n" - "End of included content.
") diff --git a/unittests/test_lines.py b/unittests/test_lines.py deleted file mode 100644 index a97f1fe..0000000 --- a/unittests/test_lines.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -from unittest import TestCase - -from markdown_include.include import IncludePreprocessor - - -class TestProcessor(TestCase): - def setUp(self) -> None: - self.maxDiff = None - self.processor = IncludePreprocessor(None, { - "base_path": os.path.dirname(os.path.realpath(__file__)), - "encoding": "utf-8", - "inheritHeadingDepth": False, - "headingOffset": 0, - "throwException": False, - }) - - def test_lines(self): - source = ["Source file", - "# Heading Level 1 of main file", - "{!resources/header.md!}", - "## Heading Level 2 of main file", - "{!resources/header.md!}"] - result_lines = self.processor.run(source) - - self.assertEqual(9, len(result_lines))