Compare commits

..
4 Commits
12 changed files with 219 additions and 1 deletions
+1
View File
@@ -41,6 +41,7 @@ source = ["omicron"]
[tool.coverage.report] [tool.coverage.report]
show_missing = true show_missing = true
exclude_also = ["@(abc\\.)?abstractmethod"]
[tool.setuptools.packages.find] [tool.setuptools.packages.find]
where = ["."] where = ["."]
@@ -0,0 +1,2 @@
name: Draft Content Test
template: plain
@@ -0,0 +1,9 @@
---
type: article
section: posts
slug: draft-post
title: Draft
date: 2026-08-28
draft: true
---
Draft.
@@ -0,0 +1,8 @@
---
type: article
section: posts
slug: published
title: Published
date: 2026-08-28
---
Published.
@@ -0,0 +1,2 @@
name: Duplicate Slug Test
template: plain
@@ -0,0 +1,8 @@
---
type: article
section: posts
slug: hello
title: First
date: 2026-08-28
---
First.
@@ -0,0 +1,8 @@
---
type: article
section: posts
slug: hello
title: Second
date: 2026-08-28
---
Second.
+2
View File
@@ -0,0 +1,2 @@
name: test
template: plain
+28
View File
@@ -0,0 +1,28 @@
import shutil
from pathlib import Path
import pytest
from omicron.ssg.site import Site
DATA_SITES = Path(__file__).parent.parent / "data" / "sites"
@pytest.fixture
def site_dir(tmp_path):
def _make(name):
path = tmp_path / name
shutil.copytree(
DATA_SITES / name,
path,
ignore=shutil.ignore_patterns("output", "build.log"),
)
return path
return _make
@pytest.fixture
def make_site(site_dir):
def _make(name, **kwargs):
return Site(site_dir(name), **kwargs)
return _make
+31
View File
@@ -0,0 +1,31 @@
from pathlib import Path
from omicron.ssg.output.file import File
def test_write_copies_content(make_site, tmp_path):
site = make_site("thin_site")
source = tmp_path / "source.txt"
source.write_text("hello")
dest_dir = site.output_path / "assets"
dest_dir.mkdir(parents=True)
file = File(site, Path("assets/copy.txt"), source)
file.write()
dest = dest_dir / "copy.txt"
assert dest.read_text() == "hello"
def test_write_overwrites_existing_destination(make_site, tmp_path):
site = make_site("thin_site")
dest = site.output_path / "copy.txt"
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text("old")
source = tmp_path / "source.txt"
source.write_text("new")
file = File(site, Path("copy.txt"), source)
file.write()
assert dest.read_text() == "new"
+38
View File
@@ -0,0 +1,38 @@
from pathlib import Path
import pytest
from omicron.ssg.output.file import File
from omicron.ssg.output.output import OutputError
def test_absolute_destination_raises(make_site, tmp_path):
site = make_site("thin_site")
with pytest.raises(OutputError):
File(site, Path("/copy.txt"), tmp_path / "source.txt")
def test_non_normalized_destination_raises(make_site, tmp_path):
site = make_site("thin_site")
with pytest.raises(OutputError):
File(site, Path("assets/../copy.txt"), tmp_path / "source.txt")
def test_site_raises_after_garbage_collection(make_site, tmp_path):
site = make_site("thin_site")
file = File(site, Path("copy.txt"), tmp_path / "source.txt")
del site
with pytest.raises(ReferenceError):
file.site
def test_url(make_site, tmp_path):
site = make_site("thin_site")
file = File(site, Path("assets/copy.txt"), tmp_path / "source.txt")
assert file.url == "/assets/copy.txt"
def test_url_strips_index_html(make_site, tmp_path):
site = make_site("thin_site")
file = File(site, Path("posts/index.html"), tmp_path / "source.txt")
assert file.url == "/posts"
+82 -1
View File
@@ -1,6 +1,7 @@
from pathlib import Path from pathlib import Path
import pytest import pytest
from omicron.ssg.site import Site from omicron.ssg.output import ContentError, Directory
from omicron.ssg.site import ConfigError, Site
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -17,3 +18,83 @@ def test_parse_base_url(value, expected_origin, expected_path):
origin, path = Site.parse_base_url(value) origin, path = Site.parse_base_url(value)
assert origin == expected_origin assert origin == expected_origin
assert path == expected_path assert path == expected_path
def test_discover_raises_on_duplicate_destination(make_site):
site = make_site("duplicate_slug")
with pytest.raises(ContentError):
site.discover()
def test_discover_creates_content_directories(make_site):
site = make_site("main")
site.discover()
assert isinstance(site.by_path[Path("posts")], Directory)
assert isinstance(site.by_path[Path("posts/first-post")], Directory)
def test_read_config_errors(site_dir):
path = site_dir("thin_site")
config_path = path / "config.yml"
config_path.unlink()
with pytest.raises(ConfigError, match="config file missing"):
Site(path)
config_path.write_text("- a\n- b\n")
with pytest.raises(ConfigError, match="YAML mapping with string keys"):
Site(path)
config_path.write_text("123: value\n")
with pytest.raises(ConfigError, match="YAML mapping with string keys"):
Site(path)
config_path.write_text("template: plain\n")
with pytest.raises(ConfigError, match="name value missing"):
Site(path)
config_path.write_text("name: test\n")
with pytest.raises(ConfigError, match="template value missing"):
Site(path)
def test_build_raises_for_relative_base_url(site_dir):
path = site_dir("thin_site")
(path / "config.yml").write_text("name: test\ntemplate: plain\nbase_url: blog\n")
site = Site(path)
with pytest.raises(ConfigError, match="absolute path"):
site.build()
def test_discover_skips_drafts_by_default(make_site):
site = make_site("draft_content")
site.discover()
assert len(site.content) == 1
assert site.content[0].title == "Published"
def test_discover_includes_drafts_when_enabled(make_site):
site = make_site("draft_content", drafts=True)
site.discover()
assert len(site.content) == 2
def test_clean_removes_output_directory(make_site):
site = make_site("main")
site.build()
assert site.output_path.exists()
site.clean()
assert not site.output_path.exists()
site.clean()
assert not site.output_path.exists()
def test_resolve_template_path_raises_for_missing_template():
with pytest.raises(ConfigError, match="not found"):
Site.resolve_template_path("does-not-exist")