pyrtan / sourcev0.14.0 · main

pyrtan / tests / test_site_source.py

2,127 bytes · last changed 2026-10-27 in Browse the source on pyrtan.com instead of linking out to GitHub

1"""site/source.py: the source browser pyrtan.com publishes at /source/."""
2
3import importlib.util
4import subprocess
5import sys
6
7from conftest import ROOT
8
9spec = importlib.util.spec_from_file_location("site_source", ROOT / "site" / "source.py")
10source = importlib.util.module_from_spec(spec)
11spec.loader.exec_module(source)
12
13
14def test_builds_from_this_checkout(tmp_path):
15 """Works on whatever git this checkout has, a shallow clone included."""
16 out = tmp_path / "source"
17 run = subprocess.run([sys.executable, "site/source.py", str(out)], capture_output=True, text=True, cwd=str(ROOT))
18 assert run.returncode == 0, run.stderr
19 for page in ("index.html", "releases.html", "branches.html", "commits.html", "tree/src/pyrtan/index.html", "blob/pyproject.toml.html"):
20 assert (out / page).is_file(), page
21 blob = (out / "blob/pyproject.toml.html").read_text()
22 assert 'id="L1"' in blob and "[project]" in blob
23 head = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, cwd=str(ROOT)).stdout.strip()
24 assert (out / f"commit/{head}.html").is_file()
25 assert 'class="md"' in (out / "index.html").read_text() # the README, rendered
26
27
28def test_markdown_escapes_and_links():
29 resolve = lambda url: "R:" + url
30 html = source.markdown("# T <b>\n\nSee [the `docs`](docs/x.md) and **<i>**.\n\n```\n<script>\n```\n\n- one\n- two\n\n| a | b |\n|---|---|\n| 1 | 2 |", resolve)
31 assert "<h1>T &lt;b&gt;</h1>" in html
32 assert '<a href="R:docs/x.md">the <code>docs</code></a>' in html
33 assert "<b>&lt;i&gt;</b>" in html
34 assert "<pre>&lt;script&gt;</pre>" in html
35 assert "<ul><li>one</li><li>two</li></ul>" in html
36 assert "<tr><td>1</td><td>2</td></tr>" in html and "---" not in html
37
38
39def test_notes_reflow_and_trailers():
40 body = "One line\nwrapped here.\n\n- a list\n- kept\n\nCo-Authored-By: X <x@example.com>"
41 assert "<p>One line wrapped here.</p>" in source.notes(body)
42 assert "- a list\n- kept" in source.notes(body)
43 assert "Co-Authored-By" in source.notes(body)
44 assert "Co-Authored-By" not in source.notes(body, trailers=False)