from pathlib import Path import pytest from omicron.ssg.output import ContentError, Directory from omicron.ssg.site import ConfigError, Site @pytest.mark.parametrize( "value, expected_origin, expected_path", [ (None, "", Path("/")), ("http://example.com/blog", "http://example.com", Path("/blog")), ("http://example.com", "http://example.com", Path("/")), ("//example.com/blog", "//example.com", Path("/blog")), ("/blog", "", Path("/blog")), ], ) def test_parse_base_url(value, expected_origin, expected_path): origin, path = Site.parse_base_url(value) assert origin == expected_origin 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")