1
0
mirror of https://codeberg.org/fediverse/fep.git synced 2026-08-05 19:55:46 +00:00

Add basic tests

This commit is contained in:
Helge
2023-06-30 15:30:21 +02:00
parent 82650c1752
commit caa6a24b67
2 changed files with 74 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
when:
branch: [main]
pipeline:
build:
image: python:3.11-alpine
commands:
- pip install pytest
- pytest
+65
View File
@@ -0,0 +1,65 @@
import pytest
import glob
import hashlib
def get_fep_ids():
for fep in glob.glob("fep/*"):
yield fep.removeprefix("fep/")
def parsefile(f):
lines = f.readlines()
status = 0
frontmatter = []
content = []
for line in lines:
if line == "---\n":
status += 1
elif status == 1:
frontmatter.append(line.removesuffix("\n"))
elif status >= 2:
content.append(line.removesuffix("\n"))
return frontmatter, content
def parse_frontmatter(frontmatter):
split = [x.split(":", 1) for x in frontmatter]
return {a: b.removeprefix(" ") for a, b in split}
@pytest.mark.parametrize("fep", get_fep_ids())
def test_fep(fep):
filename = f"fep/{fep}/fep-{fep}.md"
with open(filename) as f:
frontmatter, content = parsefile(f)
assert len(frontmatter) > 0
assert len(content) > 0
parsed_frontmatter = parse_frontmatter(frontmatter)
assert "status" in parsed_frontmatter
assert parsed_frontmatter["status"] in ["DRAFT", "FINAL"]
assert parsed_frontmatter["slug"] == f'"{fep}"'
assert "authors" in parsed_frontmatter
assert "## Summary" in content
assert "## Copyright" in content
titles = [x for x in content if x.startswith("# ")]
assert len(titles) > 0
title = titles[0]
begin_title = f"# FEP-{fep}: "
assert title.startswith(begin_title)
true_title = title.removeprefix(begin_title)
expected_slug = hashlib.sha256(true_title.encode("utf-8")).hexdigest()[:4]
assert expected_slug == fep