From 540d172011aa71b30d0d24198b27dedcab50066d Mon Sep 17 00:00:00 2001 From: shay Date: Fri, 17 Apr 2026 16:46:12 -0400 Subject: [PATCH] feat(generator): add three placeholder SVG variants Adds placeholder.py with building/rate_limited/not_found variants that use the same card_wrapper + theme system as real widgets, plus pytest coverage for all three variants and the unknown-variant error path. Co-Authored-By: Claude Sonnet 4.6 --- generator/src/placeholder.py | 28 ++++++++++++++++++++++++++++ generator/tests/test_placeholder.py | 25 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 generator/src/placeholder.py create mode 100644 generator/tests/test_placeholder.py diff --git a/generator/src/placeholder.py b/generator/src/placeholder.py new file mode 100644 index 0000000..65c3e0d --- /dev/null +++ b/generator/src/placeholder.py @@ -0,0 +1,28 @@ +"""Placeholder SVG renderer — three variants for unknown / rate-limited / not-found users. + +Uses the same card wrapper + theme system as real widgets so they look consistent. +""" +from .themes.themes import THEMES +from .utils.svg_helpers import card_wrapper, escape + +_MESSAGES = { + "building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."), + "rate_limited": ("Too many new users today", "Try again tomorrow."), + "not_found": ("GitHub user @{u} doesn't exist", "Check the spelling of the username."), +} + + +def render(variant: str, username: str, theme: str = "dark") -> str: + if variant not in _MESSAGES: + raise ValueError(f"unknown placeholder variant: {variant}") + title_tpl, subtitle = _MESSAGES[variant] + title = title_tpl.format(u=username) + palette = THEMES.get(theme, THEMES["dark"]) + + inner = ( + f'{escape(title)}' + f'{escape(subtitle)}' + ) + return card_wrapper(inner, width=400, height=120, theme=palette) diff --git a/generator/tests/test_placeholder.py b/generator/tests/test_placeholder.py new file mode 100644 index 0000000..3389c27 --- /dev/null +++ b/generator/tests/test_placeholder.py @@ -0,0 +1,25 @@ +from src import placeholder + + +def test_building_contains_username_and_svg_tag(): + svg = placeholder.render("building", "alice", theme="dark") + assert svg.startswith("" in svg + assert "alice" in svg + assert "Building" in svg or "building" in svg.lower() + + +def test_rate_limited_variant(): + svg = placeholder.render("rate_limited", "alice", theme="dark") + assert "tomorrow" in svg.lower() or "try again" in svg.lower() + + +def test_not_found_variant(): + svg = placeholder.render("not_found", "ghost", theme="dark") + assert "ghost" in svg + assert "doesn't exist" in svg or "not found" in svg.lower() + + +def test_unknown_variant_raises(): + import pytest + with pytest.raises(ValueError): + placeholder.render("bogus", "alice", theme="dark")