Spaces:
Sleeping
Sleeping
File size: 1,137 Bytes
2e818da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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"
|