58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from gettext import textdomain
|
|
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 str(steven["name"]) == "Steven"
|
|
assert str(steven["mood"]) == "Angry"
|
|
|
|
otter_list = content.load(Path("otters/otter_list.json"))
|
|
assert [str(it) for it in otter_list] == ["steven", "peter"]
|
|
|
|
|
|
def test_data_as_path(datadir: Path) -> None:
|
|
content = ContentDirectory(datadir)
|
|
paths = content.load(Path("otters/paths.yml"))
|
|
|
|
assert paths["steven"].as_path() == datadir / "otters" / "relative-steven"
|
|
|
|
|
|
def test_load_markdown(datadir: Path) -> None:
|
|
content = ContentDirectory(datadir)
|
|
page = content.load(Path("page.md"))
|
|
|
|
assert page.html == "<p>Content</p>"
|
|
assert str(page.meta["title"]) == "Title"
|
|
|
|
|
|
def test_localized_content(datadir: Path) -> None:
|
|
content = ContentDirectory(datadir)
|
|
textdomain("fr")
|
|
page = content.load(Path("page.md"))
|
|
|
|
assert page.html == "<p>Contenu</p>"
|
|
assert str(page.meta["title"]) == "Titre"
|