jean-web/tests/test_context.py

54 lines
1.9 KiB
Python

from pathlib import Path
from jwebsite.context import Context
def test_render(datadir: Path) -> None:
context = Context(datadir)
context.render("test-render.html", "output.html", animal="Otters")
with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Otters"
def test_jinja_localization(datadir: Path) -> None:
context = Context(datadir)
context.load_translations("tests", datadir / "locale", "fr")
context.render("test-jinja-localization.html", "output.html")
with open(datadir / "build" / "en" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Otters"
with open(datadir / "build" / "fr" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Loutres"
def test_load(datadir: Path) -> None:
context = Context(datadir)
context.render("test-load.html", "output.html")
with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Otters\n"
def test_load_localized(datadir: Path) -> None:
context = Context(datadir)
context.load_translations("tests", datadir / "locale", "fr")
context.render("test-load-localized.html", "output.html")
with open(datadir / "build" / "en" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Otters\nCaimans\n"
with open(datadir / "build" / "fr" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Loutres\nCaimans\n"
def test_write(datadir: Path) -> None:
context = Context(datadir)
context.render("test-write.html", "output.html")
with open(datadir / "build" / "content.txt", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Otters\n"
with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "/content.txt"