"""Tests for the notebook widgets, including the interactive World Explorer. The embedded JavaScript cannot run in this headless environment, so these tests validate the Python side and the emitted bundle rigorously: the world -> JS payload serialization is exact (parameterised laws reproduce the originals), the mimebundle is valid, self-contained HTML (balanced tags via stdlib ``HTMLParser``) carrying the integrator JS, the world-as-JSON payload, a slider per parameter and an ````, and it references no external URL. """ from __future__ import annotations from html.parser import HTMLParser import pytest from lawsynth_notebook.display import render_json from lawsynth_notebook.explorer import explore from lawsynth_notebook.explorer_math import evaluate, integrate, parse_expression from lawsynth_notebook.explorer_payload import build_payload, flatten_terms from lawsynth_notebook.widget import NotebookWidget, WorldExplorerWidget # A representative discovered Lotka-Volterra world in the exact string format the # native engine emits (coefficients baked into the arithmetic). This keeps the # core bundle/serialization tests independent of the compiled extension. LOTKA_EQUATIONS = { "x": "((1.04472645743551062e0*x)+(-3.95330420201189414e-1*(x*y)))", "y": "((-4.13098911450876627e-1*y)+(1.02763237084625800e-1*(x*y)))", } LOTKA_INITIAL = {"x": 1.5, "y": 1.0} _HTML_VOID = {"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"} class _BalanceChecker(HTMLParser): """Assert every non-void element is properly opened and closed. ``HTMLParser`` treats ``