-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from cmacmackin/unittests-ci
Add tests to CI
- Loading branch information
Showing
12 changed files
with
174 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
pytest: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install .[tests] | ||
- name: Test with pytest | ||
run: | | ||
pytest -v |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
from markdown_include.include import IncludePreprocessor, MarkdownInclude | ||
|
||
import markdown | ||
import pathlib | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
|
||
RESOURCE_DIR = pathlib.Path(__file__).parent.absolute() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def markdown_include(): | ||
return MarkdownInclude(configs={"base_path": RESOURCE_DIR}) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def markdown_include_inherit_heading_depth(): | ||
return MarkdownInclude( | ||
configs={"base_path": RESOURCE_DIR, "inheritHeadingDepth": True} | ||
) | ||
|
||
|
||
def test_single_include(markdown_include): | ||
source = "{!resources/simple.md!}" | ||
html = markdown.markdown(source, extensions=[markdown_include]) | ||
|
||
assert html == "<p>This is a simple template</p>" | ||
|
||
|
||
def test_double_include(markdown_include): | ||
source = "{!resources/simple.md!} and {!resources/simple_2.md!}" | ||
html = markdown.markdown(source, extensions=[markdown_include]) | ||
|
||
assert ( | ||
html == "<p>This is a simple template and This is another simple template</p>" | ||
) | ||
|
||
|
||
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( | ||
"""\ | ||
<p>Source file</p> | ||
<h1>Heading Level 1 of main file</h1> | ||
<h1>This heading will be one level deeper from the previous heading</h1> | ||
<p>More included file content. | ||
End of included content.</p> | ||
<h2>Heading Level 2 of main file</h2> | ||
<h1>This heading will be one level deeper from the previous heading</h1> | ||
<p>More included file content. | ||
End of included content.</p>""" | ||
) | ||
|
||
|
||
def test_embedded_template(markdown_include): | ||
source = "{!resources/template_inside.md!}" | ||
html = markdown.markdown(source, extensions=[markdown_include]) | ||
|
||
assert ( | ||
html | ||
== "<p>This is a simple template</p>\n<p>This is a template with a template.</p>" | ||
) | ||
|
||
|
||
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 == "<p>This is a simple template</p>" | ||
|
||
|
||
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 == "<p>This is a simple template and This is another simple template</p>" | ||
) | ||
|
||
|
||
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( | ||
"""\ | ||
<p>Source file</p> | ||
<h1>Heading Level 1 of main file</h1> | ||
<h2>This heading will be one level deeper from the previous heading</h2> | ||
<p>More included file content.</p> | ||
<p>End of included content.</p> | ||
<h2>Heading Level 2 of main file</h2> | ||
<h3>This heading will be one level deeper from the previous heading</h3> | ||
<p>More included file content.</p> | ||
<p>End of included content.</p>""" | ||
) | ||
|
||
|
||
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.