Files
flexly-cms/scripts/run_regression.py
T

75 lines
2.4 KiB
Python

"""Run the full suite with an isolated, migrated historical studio-site fixture.
Requires the Git history containing BASELINE. Does not restore examples in the checkout.
"""
from __future__ import annotations
import io
import subprocess
import sys
import tarfile
import tempfile
import unittest
from pathlib import Path
from site_engine.parsing.yamlio import dump_yaml, load_yaml
ROOT = Path(__file__).resolve().parents[1]
BASELINE = "231490b"
def main() -> int:
sys.path.insert(0, str(ROOT / "tests"))
import helpers
try:
archive = subprocess.run(
["git", "archive", BASELINE, "examples/studio-site"],
cwd=ROOT,
check=True,
capture_output=True,
).stdout
except (OSError, subprocess.CalledProcessError):
print(
f"Cannot read the regression fixture from Git {BASELINE}. "
"Run from a checkout with this history (fetch history for shallow clones).",
file=sys.stderr,
)
return 2
original_example = helpers.EXAMPLE
with tempfile.TemporaryDirectory(prefix="site-engine-regression-") as tmp:
with tarfile.open(fileobj=io.BytesIO(archive)) as bundle:
bundle.extractall(tmp, filter="data")
site = Path(tmp) / "examples/studio-site"
config = load_yaml((site / "site.yaml").read_text(encoding="utf-8"))
tokens = config["theme"]["tokens"]
config["theme"] = {"file": "theme.yaml"}
(site / "site.yaml").write_text(dump_yaml(config), encoding="utf-8")
# The old dark token was a custom brand color, not a semantic preset color.
# Font tokens follow minimal@1 in this migrated regression baseline.
(site / "theme.yaml").write_text(
dump_yaml({
"schema": 1,
"preset": "minimal",
"preset_version": 1,
"overrides": {
"colors": {"primary": tokens["color.primary"]},
"custom_colors": {"hero_dark": tokens["color.dark"]},
},
}),
encoding="utf-8",
)
helpers.EXAMPLE = site
try:
suite = unittest.defaultTestLoader.discover(str(ROOT / "tests"))
result = unittest.TextTestRunner(verbosity=2).run(suite)
finally:
helpers.EXAMPLE = original_example
return 0 if result.wasSuccessful() else 1
if __name__ == "__main__":
raise SystemExit(main())