Files
markdown-exec/tests/test_python.py
T
Timothée Mazzucotelli aa044f2dd9 tests: Add tests
2022-05-21 15:55:52 +02:00

64 lines
1.4 KiB
Python

"""Tests for the Python formatters."""
from textwrap import dedent
from markdown import Markdown
def test_output_markdown(md: Markdown) -> None:
"""Assert Markdown is converted to HTML.
Parameters:
md: A Markdown instance (fixture).
"""
html = md.convert(
dedent(
"""
```python exec="yes"
print("**Bold!**")
```
"""
)
)
assert html == "<p><strong>Bold!</strong></p>"
def test_output_html(md: Markdown) -> None:
"""Assert HTML is injected as is.
Parameters:
md: A Markdown instance (fixture).
"""
html = md.convert(
dedent(
"""
```python exec="yes" html="yes"
print("**Bold!**")
```
"""
)
)
assert html == "<p>**Bold!**\n</p>"
def test_error_raised(md: Markdown, caplog) -> None:
"""Assert errors properly log a warning and return a formatted traceback.
Parameters:
md: A Markdown instance (fixture).
caplog: Pytest fixture to capture logs.
"""
html = md.convert(
dedent(
"""
```python exec="yes"
raise ValueError("oh no!")
```
"""
)
)
assert "Traceback" in html
assert "ValueError" in html
assert "oh no!" in html
assert "Execution of python code block exited with non-zero status" in caplog.text