73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
|
|
"""The scaffold: it has to produce a project that builds conforming pages."""
|
||
|
|
|
||
|
|
import shutil
|
||
|
|
import subprocess
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from mews.lint import validate_file
|
||
|
|
from mews.quickstart import main, scaffold
|
||
|
|
|
||
|
|
EXPECTED = [
|
||
|
|
"pyproject.toml",
|
||
|
|
"pelicanconf.py",
|
||
|
|
"content/first-post.md",
|
||
|
|
"theme/templates/base.html",
|
||
|
|
"theme/templates/index.html",
|
||
|
|
"theme/templates/article.html",
|
||
|
|
"theme/templates/page.html",
|
||
|
|
"README.md",
|
||
|
|
]
|
||
|
|
|
||
|
|
|
||
|
|
def test_it_writes_a_whole_project(tmp_path):
|
||
|
|
scaffold(tmp_path / "site", "Signal Bars", "Tobias")
|
||
|
|
for name in EXPECTED:
|
||
|
|
assert (tmp_path / "site" / name).is_file(), name
|
||
|
|
|
||
|
|
|
||
|
|
def test_the_settings_are_valid_python(tmp_path):
|
||
|
|
scaffold(tmp_path / "site", "Signal Bars", "Tobias")
|
||
|
|
settings: dict = {}
|
||
|
|
exec(
|
||
|
|
compile((tmp_path / "site" / "pelicanconf.py").read_text(), "c", "exec"),
|
||
|
|
settings,
|
||
|
|
)
|
||
|
|
assert settings["SITENAME"] == "Signal Bars"
|
||
|
|
assert settings["PLUGINS"] == ["pelican.plugins.mews"]
|
||
|
|
# The plugin only touches this suffix, so everything has to be saved under it.
|
||
|
|
assert settings["ARTICLE_SAVE_AS"].endswith(".xhtml")
|
||
|
|
assert settings["INDEX_SAVE_AS"].endswith(".xhtml")
|
||
|
|
assert settings["MARKDOWN"]["output_format"] == "xhtml"
|
||
|
|
|
||
|
|
|
||
|
|
def test_it_refuses_a_directory_with_something_in_it(tmp_path, capsys):
|
||
|
|
(tmp_path / "site").mkdir()
|
||
|
|
(tmp_path / "site" / "keep.txt").write_text("mine")
|
||
|
|
assert main([str(tmp_path / "site"), "--no-install"]) == 1
|
||
|
|
assert (tmp_path / "site" / "keep.txt").read_text() == "mine"
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.skipif(shutil.which("uv") is None, reason="uv is not installed")
|
||
|
|
@pytest.mark.slow
|
||
|
|
def test_the_scaffolded_site_builds_conforming_pages(tmp_path):
|
||
|
|
"""The whole point: pelican runs and what it writes passes the validator."""
|
||
|
|
site = tmp_path / "site"
|
||
|
|
assert main([str(site), "--title", "Signal Bars"]) == 0
|
||
|
|
built = subprocess.run(
|
||
|
|
[shutil.which("uv"), "run", "pelican", "content"],
|
||
|
|
cwd=site,
|
||
|
|
capture_output=True,
|
||
|
|
text=True,
|
||
|
|
check=False,
|
||
|
|
)
|
||
|
|
assert built.returncode == 0, built.stderr
|
||
|
|
pages = sorted((site / "output").glob("*.xhtml"))
|
||
|
|
assert [p.name for p in pages] == ["first-post.xhtml", "index.xhtml"]
|
||
|
|
for page in pages:
|
||
|
|
report = validate_file(str(page))
|
||
|
|
assert report.conforms, "\n".join(str(f) for f in report.failures)
|
||
|
|
# Section 6.1: the index has to be subscribable.
|
||
|
|
index = (site / "output" / "index.xhtml").read_text()
|
||
|
|
assert '<li><a href="first-post.xhtml">' in index
|