Skip to content

Commit

Permalink
Merge pull request #1 from TillerBurr/test_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TillerBurr authored Dec 12, 2023
2 parents aa5d518 + 3ef393e commit 7c4b5bd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# PyMdown Extensions Blocks

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![PyPI - Version](https://img.shields.io/pypi/v/pymdownx-blocks)
[![PyPI - Version](https://img.shields.io/pypi/v/pymdownx-blocks)](https://pypi.org/project/pymdownx-blocks/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pymdownx-blocks)
![Tests](https://img.shields.io/github/actions/workflow/status/TillerBurr/pymdownx-blocks/tests)
[![Tests](https://github.com/TillerBurr/pymdownx-blocks/workflows/tests/badge.svg)](https://github.com/TillerBurr/pymdownx-blocks/actions)



Expand Down
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ dependencies = [
"pyyaml>=6.0.1",
]
readme = "README.md"
requires-python = ">= 3.12"
requires-python = ">= 3.8"
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
]

[build-system]
requires = ["hatchling"]
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
@pytest.fixture
def markdown_fixture():
def _method(
extensions: list[str] | str, extension_config: dict[str : dict[str, Any]]
extensions: list[str] | str, extension_config: dict[str , dict[str, Any]]
):
"""Fixture to dynamically insert markdown extensions."""
return markdown.Markdown(
extensions=extensions, extension_configs=extension_config
)
Expand Down
7 changes: 5 additions & 2 deletions tests/test_dirtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pymdownx_blocks.dirtree import DirTree, InvalidTreeError, InvalidYAMLError

from tests.utils import dedent, dedent_and_replace

root_dir_files = """
root_dir/:
- file1
Expand Down Expand Up @@ -98,6 +99,7 @@
def generate_dirtree_input(
placeholder: str, title: str | None = None, _type: str | None = None
):
"""Generate input for testing. Wraps the tree in the expected block format."""
if title is None:
title = ""
else:
Expand All @@ -120,6 +122,7 @@ def generate_dirtree_input(
def generate_dirtree_expected(
placeholder: str, title: str | None = None, _type: str | None = None
):
"""Generate expected output. Wraps the tree in the expected block format."""
if title is None:
title = "Directory Tree"
if _type is None:
Expand Down Expand Up @@ -148,7 +151,7 @@ def generate_dirtree_expected(
def test_build(test_input, expected_output):
dedent_in = dedent(test_input)
dedent_out = dedent(expected_output)
assert DirTree(dedent_in).build() == dedent_out
assert DirTree(dedent_in).build_tree() == dedent_out


def test_invalid_trees():
Expand All @@ -168,7 +171,7 @@ def test_invalid_yaml():


@pytest.mark.parametrize("class_type", ["note", "warning", "tip", "danger", None])
@pytest.mark.parametrize("title", ["A Title", "AnotherTitle",None])
@pytest.mark.parametrize("title", ["A Title", "AnotherTitle", None])
def test_title(markdown_fixture, class_type, title):
md = markdown_fixture(
["pymdownx_blocks.dirtree"], extension_config={"pymdownx_blocks.dirtree": []}
Expand Down
21 changes: 20 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import textwrap


def dedent(text: str) -> str:
"""Dedent an indented string by the miniumum indentation level.
Args:
text: String to dedent
Returns:
dedented string
"""
return textwrap.dedent(text).strip("\n")


def dedent_and_replace(
to_dedent: str, to_replace: str, new: str, dedent_new: bool = True
) -> str:
"""Dedent and replace a string.
Args:
to_dedent: String to dedent
to_replace: String to replace
new: String to replace with
dedent_new: Bool that is true if `new` should also be dedented.
Returns:
"""
if dedent_new:
new = dedent(new)
return dedent(to_dedent).replace(to_replace, new)

0 comments on commit 7c4b5bd

Please sign in to comment.