Add the shared document API, constructor and expert editors, isolated preview, and fragment catalog metadata with typed block IDs. Include design references, specification 001, QA scripts, project guidance, and cached Docker dependency installation. Leave example sites for a separate commit.
59 lines
3.4 KiB
Python
59 lines
3.4 KiB
Python
"""Регрессия: в установленный пакет (Docker-образ, wheel) должны попасть шаблоны и статика админки,
|
|
встроенные фрагменты и стили. Раньше package-data включал только builtin/."""
|
|
|
|
import fnmatch
|
|
import glob
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import tomllib
|
|
import unittest
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
PKG = ROOT / "src" / "site_engine"
|
|
|
|
|
|
class PackagingTest(unittest.TestCase):
|
|
def test_package_data_patterns_cover_every_runtime_file(self):
|
|
patterns = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))["tool"]["setuptools"]["package-data"]["site_engine"]
|
|
runtime = [p for sub in ("builtin", "web/admin/templates", "web/admin/static") for p in (PKG / sub).rglob("*")
|
|
if p.is_file() and p.suffix != ".pyc" and "__pycache__" not in p.parts]
|
|
self.assertGreater(len(runtime), 50)
|
|
uncovered = [str(p.relative_to(PKG)) for p in runtime
|
|
if not any(fnmatch.fnmatch(p.relative_to(PKG).as_posix(), pat.replace("**/*", "*")) for pat in patterns)]
|
|
self.assertEqual(uncovered, [])
|
|
|
|
def test_built_wheel_contains_templates_static_and_fragments(self):
|
|
try:
|
|
import setuptools # noqa: F401
|
|
except ImportError:
|
|
self.skipTest("нет setuptools")
|
|
before = {name: (ROOT / name).exists() for name in ("build", "src/site_engine.egg-info")}
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
project = Path(tmp) / "project"
|
|
shutil.copytree(ROOT, project, ignore=shutil.ignore_patterns(
|
|
"build", "*.egg-info", "__pycache__", ".git", "tests", "docs", "examples", "dist", ".engine"))
|
|
result = subprocess.run([sys.executable, "-m", "pip", "wheel", str(project), "--no-deps", "--no-build-isolation",
|
|
"-q", "-w", str(Path(tmp) / "out")], capture_output=True, text=True, timeout=180)
|
|
wheels = glob.glob(f"{tmp}/out/*.whl")
|
|
if result.returncode != 0 or not wheels:
|
|
self.skipTest(f"wheel не собрался в этом окружении: {result.stderr[-200:]}")
|
|
names = zipfile.ZipFile(wheels[0]).namelist()
|
|
after = {name: (ROOT / name).exists() for name in before}
|
|
self.assertEqual(after, before, "сборка wheel не должна оставлять мусор в рабочем каталоге")
|
|
for needed in ("site_engine/web/admin/templates/login.html.j2", "site_engine/web/admin/templates/page_edit.html.j2",
|
|
"site_engine/web/admin/static/admin.css", "site_engine/web/admin/static/htmx.min.js",
|
|
"site_engine/web/admin/static/VENDOR.md", "site_engine/web/admin/static/admin.js",
|
|
"site_engine/web/admin/static/editor.js", "site_engine/web/admin/static/preview.js",
|
|
"site_engine/web/admin/templates/document.html.j2", "site_engine/web/admin/templates/editor_result.html.j2",
|
|
"site_engine/web/admin/templates/preview_result.html.j2", "site_engine/builtin/base.css",
|
|
"site_engine/builtin/fragments/hero/template.html.j2"):
|
|
self.assertIn(needed, names)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|