61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
"""Nox configuration file."""
|
|
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
|
|
from nox import Session, session
|
|
|
|
_LOCALIZED_TESTS = ["tests/test_context"]
|
|
|
|
|
|
@session()
|
|
def lint(session: Session) -> None:
|
|
session.install("ruff")
|
|
session.run("ruff", "check", "--fix")
|
|
session.run("ruff", "format")
|
|
|
|
|
|
@session()
|
|
def mypy(session: Session) -> None:
|
|
session.install("-e", ".[dev]", "mypy", "types-PyYAML", "types-Markdown")
|
|
session.run("mypy")
|
|
|
|
|
|
@session()
|
|
def update_messages(session: Session) -> None:
|
|
session.install("babel", "jinja2")
|
|
for directory in _LOCALIZED_TESTS:
|
|
with TemporaryDirectory() as tmp_dir:
|
|
messages_file = Path(tmp_dir) / "messages.po"
|
|
session.run(
|
|
"pybabel",
|
|
"extract",
|
|
"--mapping",
|
|
f"{directory}/babel.cfg",
|
|
f"--output-file={messages_file}",
|
|
str(directory),
|
|
)
|
|
|
|
session.run(
|
|
"pybabel",
|
|
"update",
|
|
"--domain=tests",
|
|
f"--input-file={messages_file}",
|
|
f"--output-dir={directory}/locale",
|
|
)
|
|
|
|
|
|
@session(python=["3.10", "3.11"])
|
|
def unit_tests(session: Session) -> None:
|
|
"""Run unit tests."""
|
|
devenv(session)
|
|
session.install("babel", "jinja2")
|
|
for directory in _LOCALIZED_TESTS:
|
|
session.run("pybabel", "compile", "--domain=tests", f"--directory={directory}/locale", "--use-fuzzy")
|
|
session.run("python", "-m", "pytest", "--cov=jwebsite", "--cov-report=html")
|
|
|
|
|
|
@session()
|
|
def devenv(session: Session) -> None:
|
|
session.install("-e", ".[dev]")
|