Compare commits

...
4 Commits
Author SHA1 Message Date
omicron 9d5387a40a Add Makefile with targets for common actions 2026-08-28 01:58:52 +02:00
omicron 82f60f3d75 Set up e2e testing 2026-08-28 01:44:38 +02:00
omicron 6afc8585db Set up pytest and coverage tooling 2026-08-28 01:15:28 +02:00
omicron 34df950cbd Make site building output deterministic
In order to do snapshot testing of the site output we want the output to
always be the same regardless of how the filesystem tree was created
2026-08-28 01:08:58 +02:00
8 changed files with 109 additions and 1 deletions
+4
View File
@@ -2,3 +2,7 @@
__pycache__ __pycache__
*.egg-info *.egg-info
*.pyc *.pyc
.coverage
htmlcov/
tests/data/sites/*/output/
tests/data/sites/*/build.log
+29
View File
@@ -0,0 +1,29 @@
TEST_SITE := tests/data/sites/main
OUTPUT := $(TEST_SITE)/output
.PHONY: build build-drafts check test coverage clean serve
build:
OSSG_TYPECHECKED="1" ossg --site $(TEST_SITE) -v build
build-drafts:
OSSG_TYPECHECKED="1" ossg --site $(TEST_SITE) -v build --drafts
check:
mypy -p omicron.ssg
black --check omicron tests/unit tests/e2e
test:
pytest
coverage:
coverage run -m pytest tests/unit
coverage report
coverage html
@echo "file://$(CURDIR)/htmlcov/index.html"
clean:
ossg --site $(TEST_SITE) clean
serve:
python -m http.server --bind 127.0.0.1 --directory $(OUTPUT)
+2 -1
View File
@@ -185,7 +185,8 @@ class Site:
self.other_outputs.append(pygments) self.other_outputs.append(pygments)
self.add_by_path(pygments) self.add_by_path(pygments)
content_path = self.site_path / "content" content_path = self.site_path / "content"
for file in content_path.rglob("*"): files = sorted(content_path.rglob("*"))
for file in files:
if file.is_file() and is_content(file): if file.is_file() and is_content(file):
content = create_content(self, file) content = create_content(self, file)
if content.draft and not self.drafts: if content.draft and not self.drafts:
+11
View File
@@ -17,7 +17,9 @@ dependencies = [
dev = [ dev = [
"beartype", "beartype",
"black", "black",
"coverage",
"mypy", "mypy",
"pytest",
"types-PyYAML", "types-PyYAML",
"types-Pygments", "types-Pygments",
] ]
@@ -31,6 +33,15 @@ target-version = ["py314"]
[tool.mypy] [tool.mypy]
strict = true strict = true
[tool.pytest.ini_options]
testpaths = ["tests"]
[tool.coverage.run]
source = ["omicron"]
[tool.coverage.report]
show_missing = true
[tool.setuptools.packages.find] [tool.setuptools.packages.find]
where = ["."] where = ["."]
include = ["omicron.ssg*"] include = ["omicron.ssg*"]
+3
View File
@@ -0,0 +1,3 @@
name: Main Test Site
base_url: http://127.0.0.1:8000
template: plain
@@ -0,0 +1,10 @@
---
type: article
section: posts
slug: first-post
title: First Post
date: 2026-08-28
tags: [meta]
---
Welcome to the test site. This site will contain some test content for the
static site generator, the content won't matter a lot.
+31
View File
@@ -0,0 +1,31 @@
import shutil
import subprocess
from pathlib import Path
import pytest
MAIN_SITE = Path(__file__).parent.parent / "data" / "sites" / "main"
@pytest.fixture(scope="module")
def built_site(tmp_path_factory):
site_dir = tmp_path_factory.mktemp("main")
shutil.copytree(
MAIN_SITE,
site_dir,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns("output", "build.log"),
)
result = subprocess.run(
["ossg", "--site", str(site_dir), "build"],
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr
return site_dir / "output"
def test_article_renders(built_site):
output = built_site / "posts" / "first-post" / "index.html"
assert output.exists()
assert "First Post" in output.read_text()
+19
View File
@@ -0,0 +1,19 @@
from pathlib import Path
import pytest
from omicron.ssg.site import 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