From 75ea5ed1a69d7a210234f46d9d6410a0029aad17 Mon Sep 17 00:00:00 2001 From: propcgamer20-png Date: Tue, 18 Aug 2026 20:44:24 +0530 Subject: [PATCH] Enhance tests for SVG logo parsing Added tests for parsing SVG logos, including validation for viewBox and rectangle constraints. --- tests/test_generate_images.py | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/test_generate_images.py b/tests/test_generate_images.py index 141e2ec..220829f 100644 --- a/tests/test_generate_images.py +++ b/tests/test_generate_images.py @@ -1,9 +1,82 @@ import importlib +import pytest from PIL import Image import json import shutil +_VALID_SVG = """ + + + + +""" + + +def test_parse_mark_accepts_the_real_logo_svg(): + script = importlib.import_module("scripts.generate_favicons") + + spec = script._parse_mark(script.ROOT / "assets" / "icons" / "logo.svg") + + assert spec["size"] == 100.0 + assert spec["mark_fill"] == "#14171A" + assert spec["accent_fill"] == "#4F7A5B" + + +def test_parse_mark_rejects_non_square_viewbox(tmp_path): + script = importlib.import_module("scripts.generate_favicons") + bad_svg = tmp_path / "bad.svg" + bad_svg.write_text( + _VALID_SVG.replace('viewBox="0 0 100 100"', 'viewBox="0 0 100 80"'), + encoding="utf-8", + ) + + with pytest.raises(ValueError, match="expected a square viewBox starting at 0,0"): + script._parse_mark(bad_svg) + + +def test_parse_mark_rejects_viewbox_not_at_origin(tmp_path): + script = importlib.import_module("scripts.generate_favicons") + bad_svg = tmp_path / "bad.svg" + bad_svg.write_text( + _VALID_SVG.replace('viewBox="0 0 100 100"', 'viewBox="10 0 100 100"'), + encoding="utf-8", + ) + + with pytest.raises(ValueError, match="expected a square viewBox starting at 0,0"): + script._parse_mark(bad_svg) + + +def test_parse_mark_rejects_a_fourth_rect(tmp_path): + script = importlib.import_module("scripts.generate_favicons") + bad_svg = tmp_path / "bad.svg" + bad_svg.write_text( + _VALID_SVG.replace( + "", + ' \n', + ), + encoding="utf-8", + ) + + with pytest.raises(ValueError, match="no longer exactly three rects"): + script._parse_mark(bad_svg) + + +def test_parse_mark_rejects_mismatched_stem_and_bar_fill(tmp_path): + script = importlib.import_module("scripts.generate_favicons") + bad_svg = tmp_path / "bad.svg" + bad_svg.write_text( + _VALID_SVG.replace( + '', + '', + ), + encoding="utf-8", + ) + + with pytest.raises(ValueError, match="stem and top bar are expected to share one fill color"): + script._parse_mark(bad_svg) + + def test_generate_favicons(tmp_path): script = importlib.import_module("scripts.generate_favicons")