""" test_compilers.py — Test suite for xml2svg.py and constraint_graph_svg.py """ import os import sys import traceback # ─── Test infrastructure ────────────────────────────────────────────────────── passed = 0 failed = 0 def test(name: str, fn): global passed, failed try: fn() print(f" PASS {name}") passed += 1 except Exception as e: print(f" FAIL {name}") traceback.print_exc() failed += 1 # ─── Load examples ──────────────────────────────────────────────────────────── HERE = os.path.dirname(os.path.abspath(__file__)) EXAMPLES = os.path.join(HERE, "examples") with open(os.path.join(EXAMPLES, "scene.xml"), encoding="utf-8") as f: SCENE_XML = f.read() with open(os.path.join(EXAMPLES, "constraint_graph.xml"), encoding="utf-8") as f: GRAPH_XML = f.read() # ─── Import compilers ───────────────────────────────────────────────────────── from xml2svg import XMLToSVG from constraint_graph_svg import ConstraintGraphCompiler # ─── Tests ─────────────────────────────────────────────────────────────────── print("\nRunning tests...\n") # 1. XMLToSVG compiles scene.xml → valid SVG def test_xml2svg_scene(): compiler = XMLToSVG() svg = compiler.compile(SCENE_XML) assert " def test_xml2svg_wrong_root(): compiler = XMLToSVG() xml = '' try: compiler.compile(xml) raise AssertionError("Should have raised ValueError") except ValueError as e: assert "scene" in str(e).lower() test("XMLToSVG raises ValueError if root is not ", test_xml2svg_wrong_root) # 4. ConstraintGraphCompiler compile_to_svg produces valid SVG with all 7 node types def test_cg_svg_all_types(): compiler = ConstraintGraphCompiler() svg = compiler.compile_to_svg(GRAPH_XML) assert "