Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions data/repos_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,13 +868,6 @@
"eyebrow": "workbench",
"headline": "workbench — the browser IDE and MicroPython simulator.",
"description": "A ViperIDE fork with a built-in WebAssembly MicroPython simulator: edit, run, and debug PyDevices code against a simulated board entirely in the browser, no hardware required.",
"hero_canvas": {
"app": "polyhedron",
"width": 240,
"height": 240,
"shape": "square",
"app_url": "https://PyDevices.github.io/assets/apps/polyhedron.py"
},
"buttons": [
{
"label": "GitHub Repo",
Expand Down
5 changes: 5 additions & 0 deletions scripts/generate_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def validate_db(db, only=None):
problems.append(
f'{name}: page {destination!r} is not one of {sorted(valid_pages)}'
)
# page=none generates no landing page, so a hero there runs nowhere.
if destination == 'none' and data.get('hero_canvas'):
problems.append(
f'{name}: hero_canvas on page=none; nothing generates a page to show it'
)
# A repo keeping its own Pages must still have somewhere to publish from.
if on_disk and destination == 'self' and not os.path.isdir(
os.path.join(BASE_DIR, name, '.site')
Expand Down
55 changes: 55 additions & 0 deletions tests/test_validate_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""validate_db() catches database entries that generate nothing anyone serves."""

from __future__ import annotations

import copy
import json
import sys
import unittest
from pathlib import Path

REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))

import generate_sites


def _db() -> dict:
return json.loads((REPO / "data/repos_db.json").read_text(encoding="utf-8"))


class HeroCanvasTests(unittest.TestCase):
def setUp(self) -> None:
# The script finds its assets through the workspace layout; a checkout
# anywhere else (a worktree) still has them beside these tests.
saved = generate_sites.ASSETS_DIR
generate_sites.ASSETS_DIR = str(REPO / "assets")
self.addCleanup(setattr, generate_sites, "ASSETS_DIR", saved)

def _problems(self, db: dict) -> list[str]:
try:
generate_sites.validate_db(db, only="__none__")
except SystemExit as exc:
return [line.strip() for line in str(exc).splitlines()]
return []

def test_database_has_no_hero_on_a_page_nobody_generates(self) -> None:
unserved = [
name for name, data in generate_sites.repos(_db()).items()
if data.get("hero_canvas") and generate_sites.page_destination(data) == "none"
]
self.assertEqual(unserved, [])

def test_validator_rejects_a_hero_on_page_none(self) -> None:
db = copy.deepcopy(_db())
name = next(n for n, d in generate_sites.repos(db).items() if d.get("hero_canvas"))
db[name]["page"] = "none"
problems = self._problems(db)
self.assertTrue(
any(p.startswith(f"{name}: hero_canvas") and "page=none" in p for p in problems),
problems,
)


if __name__ == "__main__":
unittest.main()
Loading