Consolidate test site fixture into a single make_site

This commit is contained in:
2026-09-03 03:10:13 +02:00
parent 2835b77146
commit 1fe2bbd1db
4 changed files with 39 additions and 21 deletions
+2
View File
@@ -0,0 +1,2 @@
name: test
template: plain
+15 -3
View File
@@ -1,8 +1,20 @@
import shutil
from pathlib import Path
import pytest import pytest
from omicron.ssg.site import Site from omicron.ssg.site import Site
DATA_SITES = Path(__file__).parent.parent / "data" / "sites"
@pytest.fixture @pytest.fixture
def thin_site(tmp_path): def make_site(tmp_path):
(tmp_path / "config.yml").write_text("name: test\ntemplate: plain\n") def _make(name, **kwargs):
return Site(tmp_path) site_dir = tmp_path / name
shutil.copytree(
DATA_SITES / name,
site_dir,
ignore=shutil.ignore_patterns("output", "build.log"),
)
return Site(site_dir, **kwargs)
return _make
+8 -6
View File
@@ -2,28 +2,30 @@ from pathlib import Path
from omicron.ssg.output.file import File from omicron.ssg.output.file import File
def test_write_copies_content(thin_site, tmp_path): def test_write_copies_content(make_site, tmp_path):
site = make_site("thin_site")
source = tmp_path / "source.txt" source = tmp_path / "source.txt"
source.write_text("hello") source.write_text("hello")
dest_dir = thin_site.output_path / "assets" dest_dir = site.output_path / "assets"
dest_dir.mkdir(parents=True) dest_dir.mkdir(parents=True)
file = File(thin_site, Path("assets/copy.txt"), source) file = File(site, Path("assets/copy.txt"), source)
file.write() file.write()
dest = dest_dir / "copy.txt" dest = dest_dir / "copy.txt"
assert dest.read_text() == "hello" assert dest.read_text() == "hello"
def test_write_overwrites_existing_destination(thin_site, tmp_path): def test_write_overwrites_existing_destination(make_site, tmp_path):
dest = thin_site.output_path / "copy.txt" site = make_site("thin_site")
dest = site.output_path / "copy.txt"
dest.parent.mkdir(parents=True, exist_ok=True) dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text("old") dest.write_text("old")
source = tmp_path / "source.txt" source = tmp_path / "source.txt"
source.write_text("new") source.write_text("new")
file = File(thin_site, Path("copy.txt"), source) file = File(site, Path("copy.txt"), source)
file.write() file.write()
assert dest.read_text() == "new" assert dest.read_text() == "new"
+14 -12
View File
@@ -2,22 +2,22 @@ from pathlib import Path
import pytest import pytest
from omicron.ssg.output.file import File from omicron.ssg.output.file import File
from omicron.ssg.output.output import OutputError from omicron.ssg.output.output import OutputError
from omicron.ssg.site import Site
def test_absolute_destination_raises(thin_site, tmp_path): def test_absolute_destination_raises(make_site, tmp_path):
site = make_site("thin_site")
with pytest.raises(OutputError): with pytest.raises(OutputError):
File(thin_site, Path("/copy.txt"), tmp_path / "source.txt") File(site, Path("/copy.txt"), tmp_path / "source.txt")
def test_non_normalized_destination_raises(thin_site, tmp_path): def test_non_normalized_destination_raises(make_site, tmp_path):
site = make_site("thin_site")
with pytest.raises(OutputError): with pytest.raises(OutputError):
File(thin_site, Path("assets/../copy.txt"), tmp_path / "source.txt") File(site, Path("assets/../copy.txt"), tmp_path / "source.txt")
def test_site_raises_after_garbage_collection(tmp_path): def test_site_raises_after_garbage_collection(make_site, tmp_path):
(tmp_path / "config.yml").write_text("name: test\ntemplate: plain\n") site = make_site("thin_site")
site = Site(tmp_path)
file = File(site, Path("copy.txt"), tmp_path / "source.txt") file = File(site, Path("copy.txt"), tmp_path / "source.txt")
del site del site
@@ -26,11 +26,13 @@ def test_site_raises_after_garbage_collection(tmp_path):
file.site file.site
def test_url(thin_site, tmp_path): def test_url(make_site, tmp_path):
file = File(thin_site, Path("assets/copy.txt"), tmp_path / "source.txt") site = make_site("thin_site")
file = File(site, Path("assets/copy.txt"), tmp_path / "source.txt")
assert file.url == "/assets/copy.txt" assert file.url == "/assets/copy.txt"
def test_url_strips_index_html(thin_site, tmp_path): def test_url_strips_index_html(make_site, tmp_path):
file = File(thin_site, Path("posts/index.html"), tmp_path / "source.txt") site = make_site("thin_site")
file = File(site, Path("posts/index.html"), tmp_path / "source.txt")
assert file.url == "/posts" assert file.url == "/posts"