Compare commits
4
Commits
a0fa7d8fe2
...
9d5387a40a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d5387a40a | ||
|
|
82f60f3d75 | ||
|
|
6afc8585db | ||
|
|
34df950cbd |
@@ -2,3 +2,7 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
*.egg-info
|
*.egg-info
|
||||||
*.pyc
|
*.pyc
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
tests/data/sites/*/output/
|
||||||
|
tests/data/sites/*/build.log
|
||||||
|
|||||||
@@ -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
@@ -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:
|
||||||
|
|||||||
@@ -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*"]
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -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()
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user