study-buddy / tests /agents /d3 /test_engine.py
GitHub Actions
deploy d092bea3608b7a29952f16357fda39b7a29e399b
2e818da
Raw
History Blame Contribute Delete
1.14 kB
from app.agents.d3.engine import D3Engine
from app.agents.d3.router import D3Selection
from app.agents.d3.registry import TEMPLATES
from app.agents.d3 import templates # noqa: F401
class _Router:
def __init__(self, sel): self._sel = sel
def select(self, *a, **k): return self._sel
class _Extractor:
def __init__(self, out): self._out = out
def fill(self, *a, **k): return self._out
def test_engine_renders_d3_payload():
t = TEMPLATES["bar_chart"]
eng = D3Engine(router=_Router(D3Selection(template_id="bar_chart")),
extractor=_Extractor(t.golden_sample))
out = eng.generate("GDP", [{"source": "s", "text": "US 21"}], "graduate")
assert out.animation_type == "graph" and "__DATA__" not in out.html_code
def test_engine_never_declines_even_with_unrelated_source():
t = TEMPLATES["bar_chart"]
eng = D3Engine(router=_Router(D3Selection(template_id="bar_chart")),
extractor=_Extractor(t.golden_sample))
out = eng.generate("justice", [{"source": "s", "text": "philosophy, unrelated to any chart"}], "graduate")
assert out.animation_type == "graph"