41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
from pytest import raises
|
|
|
|
from jwebsite.content import ContentDirectory
|
|
|
|
|
|
def test_load_directory(datadir: Path) -> None:
|
|
content = ContentDirectory(datadir)
|
|
otters = content.load(Path("otters"))
|
|
assert isinstance(otters, ContentDirectory)
|
|
|
|
|
|
def test_load_errors(datadir: Path) -> None:
|
|
directory = ContentDirectory(datadir)
|
|
|
|
with raises(FileNotFoundError):
|
|
directory.load(Path("otters/i-dont-exist"))
|
|
|
|
with raises(NotADirectoryError):
|
|
directory.load(Path("otters/steven.yml/child"))
|
|
|
|
|
|
def test_load_data(datadir: Path) -> None:
|
|
content = ContentDirectory(datadir)
|
|
steven = content.load(Path("otters/steven.yml"))
|
|
|
|
assert steven["name"] == "Steven"
|
|
assert steven["mood"] == "Angry"
|
|
|
|
otter_list = content.load(Path("otters/otter_list.json"))
|
|
assert list(otter_list) == ["steven", "peter"]
|
|
|
|
|
|
def test_load_markdown(datadir: Path) -> None:
|
|
content = ContentDirectory(datadir)
|
|
page = content.load(Path("page.md"))
|
|
|
|
assert page.html == "<p>Content</p>"
|
|
assert page.meta["title"] == "Title"
|