Expand tests for Site
This commit is contained in:
+13
-5
@@ -7,14 +7,22 @@ DATA_SITES = Path(__file__).parent.parent / "data" / "sites"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_site(tmp_path):
|
||||
def _make(name, **kwargs):
|
||||
site_dir = tmp_path / name
|
||||
def site_dir(tmp_path):
|
||||
def _make(name):
|
||||
path = tmp_path / name
|
||||
shutil.copytree(
|
||||
DATA_SITES / name,
|
||||
site_dir,
|
||||
path,
|
||||
ignore=shutil.ignore_patterns("output", "build.log"),
|
||||
)
|
||||
return Site(site_dir, **kwargs)
|
||||
return path
|
||||
|
||||
return _make
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_site(site_dir):
|
||||
def _make(name, **kwargs):
|
||||
return Site(site_dir(name), **kwargs)
|
||||
|
||||
return _make
|
||||
|
||||
+82
-1
@@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
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(
|
||||
@@ -17,3 +18,83 @@ 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")
|
||||
|
||||
Reference in New Issue
Block a user