39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from pathlib import Path
|
|
|
|
from pytest import mark, raises
|
|
|
|
from jwebsite.content import Content
|
|
from jwebsite.context import Context
|
|
|
|
|
|
@mark.parametrize("content", ["# Otters", b"# Otters"])
|
|
def test_load(datadir: Path, content: bytes | str) -> None:
|
|
context = Context(datadir)
|
|
context.load_extensions("jwebsite.extensions.markdown")
|
|
|
|
context.render("test-load.html", "output.html", content=Content(Path("content.yml"), content, None))
|
|
with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file:
|
|
assert ouput_file.read() == "<h1>Otters</h1>"
|
|
|
|
|
|
def test_load_type_error(datadir: Path) -> None:
|
|
context = Context(datadir)
|
|
context.load_extensions("jwebsite.extensions.markdown")
|
|
|
|
with raises(ValueError):
|
|
context.render("test-load.html", "output.html", content=Content(Path("content.yml"), 10, None))
|
|
|
|
with raises(ValueError):
|
|
context.render("test-load.html", "output.html", content=10)
|
|
|
|
|
|
def test_metadata(datadir: Path) -> None:
|
|
context = Context(datadir)
|
|
context.load_extensions("jwebsite.extensions.markdown")
|
|
|
|
markdown = "---\n" "title: Steven\n" "---\n" "\n" "Content\n"
|
|
|
|
context.render("test-metadata.html", "output.html", content=Content(Path("content.yml"), markdown, None))
|
|
with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file:
|
|
assert ouput_file.read() == "Steven"
|