63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
import ast
|
||
|
|
import json
|
||
|
|
import unittest
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
ROOT = Path(__file__).resolve().parents[1]
|
||
|
|
|
||
|
|
|
||
|
|
class RepositoryTests(unittest.TestCase):
|
||
|
|
def test_machine_readable_files_parse(self) -> None:
|
||
|
|
for name in ("repository.json", "repository-variables.json", "content-index.json"):
|
||
|
|
with self.subTest(name=name):
|
||
|
|
json.loads((ROOT / name).read_text(encoding="utf-8"))
|
||
|
|
|
||
|
|
def test_versions_align(self) -> None:
|
||
|
|
version = (ROOT / "VERSION").read_text(encoding="utf-8").strip()
|
||
|
|
manifest = json.loads((ROOT / "repository.json").read_text(encoding="utf-8"))
|
||
|
|
citation = (ROOT / "CITATION.cff").read_text(encoding="utf-8")
|
||
|
|
self.assertEqual(version, manifest["version"])
|
||
|
|
self.assertIn(f"version: {version}", citation)
|
||
|
|
|
||
|
|
def test_declared_paths_exist(self) -> None:
|
||
|
|
manifest = json.loads((ROOT / "repository.json").read_text(encoding="utf-8"))
|
||
|
|
paths = [
|
||
|
|
manifest["entrypoints"]["human"],
|
||
|
|
manifest["entrypoints"]["ai"],
|
||
|
|
*[
|
||
|
|
value
|
||
|
|
for key, value in manifest["entrypoints"].items()
|
||
|
|
if key not in {"human", "ai"} and value
|
||
|
|
],
|
||
|
|
*[item["path"] for item in manifest["contents"]],
|
||
|
|
]
|
||
|
|
for path in paths:
|
||
|
|
with self.subTest(path=path):
|
||
|
|
self.assertTrue((ROOT / path).exists())
|
||
|
|
|
||
|
|
def test_content_index_integrity(self) -> None:
|
||
|
|
index = json.loads((ROOT / "content-index.json").read_text(encoding="utf-8"))
|
||
|
|
ids = [item["content_id"] for item in index["items"]]
|
||
|
|
paths = [item["path"] for item in index["items"]]
|
||
|
|
self.assertEqual(13, len(index["items"]))
|
||
|
|
self.assertEqual(len(ids), len(set(ids)))
|
||
|
|
self.assertEqual(len(paths), len(set(paths)))
|
||
|
|
for path in paths:
|
||
|
|
with self.subTest(path=path):
|
||
|
|
self.assertTrue((ROOT / path).is_file())
|
||
|
|
|
||
|
|
def test_python_syntax(self) -> None:
|
||
|
|
python_files = sorted((ROOT / "api").rglob("*.py")) + sorted(
|
||
|
|
(ROOT / "skills-scripts").rglob("*.py")
|
||
|
|
)
|
||
|
|
self.assertTrue(python_files)
|
||
|
|
for path in python_files:
|
||
|
|
with self.subTest(path=path.relative_to(ROOT).as_posix()):
|
||
|
|
ast.parse(path.read_text(encoding="utf-8-sig"), filename=str(path))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|