Skip to content

Commit

Permalink
Merge pull request #38 from cmacmackin/unittests-ci
Browse files Browse the repository at this point in the history
Add tests to CI
  • Loading branch information
ZedThree authored Nov 23, 2022
2 parents 53f5e3c + 40109fb commit 692e499
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 190 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/tests.yaml
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
54 changes: 0 additions & 54 deletions README.rst

This file was deleted.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ dependencies = [
]
dynamic = ["version"]

[project.optional-dependencies]
tests = [
"pytest",
]

[tool.setuptools]
packages = ["markdown_include"]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
144 changes: 144 additions & 0 deletions tests/test_include.py
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
20 changes: 0 additions & 20 deletions unittests/test_embedded.py

This file was deleted.

45 changes: 0 additions & 45 deletions unittests/test_include.py

This file was deleted.

45 changes: 0 additions & 45 deletions unittests/test_include_header_indent.py

This file was deleted.

26 changes: 0 additions & 26 deletions unittests/test_lines.py

This file was deleted.

0 comments on commit 692e499

Please # to comment.