test(notebooks): section-5 tolerance test asserts the rendered tag table (refs #688)
This commit is contained in:
@@ -7,6 +7,8 @@ import importlib.util
|
|||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import marimo as mo
|
||||||
|
|
||||||
NB = Path(__file__).resolve().parents[2] / "notebooks" / "code_families.py"
|
NB = Path(__file__).resolve().parents[2] / "notebooks" / "code_families.py"
|
||||||
|
|
||||||
|
|
||||||
@@ -49,15 +51,42 @@ def test_headless_run_degrades_without_data(monkeypatch, tmp_path):
|
|||||||
assert result is not None
|
assert result is not None
|
||||||
|
|
||||||
|
|
||||||
|
def _tables_in(obj):
|
||||||
|
"""Every mo.ui.table nested under a marimo cell output — mo.vstack
|
||||||
|
(and other containers) expose their children as live objects via
|
||||||
|
``_live_children``, not just pre-rendered HTML, so a table's full
|
||||||
|
``.data`` (not the ~10-row preview ``_repr_html_`` embeds) is
|
||||||
|
reachable for assertions."""
|
||||||
|
found = []
|
||||||
|
if isinstance(obj, mo.ui.table):
|
||||||
|
found.append(obj)
|
||||||
|
for child in getattr(obj, "_live_children", None) or []:
|
||||||
|
found.extend(_tables_in(child))
|
||||||
|
return found
|
||||||
|
|
||||||
|
|
||||||
def test_section5_tolerates_missing_llm_db_password(monkeypatch):
|
def test_section5_tolerates_missing_llm_db_password(monkeypatch):
|
||||||
"""Section 5's pgvector chunk-count lookup must degrade to a note,
|
"""Section 5's pgvector chunk-count lookup must degrade to a note,
|
||||||
never raise, when LLM_DB_PASSWORD is unset — the bib item-tag counts
|
never raise, when LLM_DB_PASSWORD is unset — the bib item-tag counts
|
||||||
still render (task-8-context.md: "the section-5 cell must render the
|
still render (task-8-context.md: "the section-5 cell must render the
|
||||||
bib tag counts with a note when it is missing, and never raise")."""
|
bib tag counts with a note when it is missing, and never raise").
|
||||||
|
|
||||||
|
The note-text assertions alone are vacuous — they'd pass even if
|
||||||
|
``store.list_tags`` raised, since the note text sits in the cell's
|
||||||
|
intro prose. So also require the ``family:*`` tag table to have
|
||||||
|
actually rendered (a mo.ui.table only appears on the list_tags
|
||||||
|
success path — the ``except`` branch builds no table at all) and to
|
||||||
|
carry a real, live row: ``family:CCM`` with a positive count.
|
||||||
|
"""
|
||||||
monkeypatch.delenv("LLM_DB_PASSWORD", raising=False)
|
monkeypatch.delenv("LLM_DB_PASSWORD", raising=False)
|
||||||
mod = _load()
|
mod = _load()
|
||||||
outputs, _defs = mod.app.run() # real replica/bib — data symlinks are in place
|
outputs, _defs = mod.app.run() # real replica/bib — data symlinks are in place
|
||||||
rendered = "\n".join(o._repr_html_() for o in outputs if hasattr(o, "_repr_html_"))
|
rendered = "\n".join(o._repr_html_() for o in outputs if hasattr(o, "_repr_html_"))
|
||||||
assert "LLM_DB_PASSWORD" in rendered and "not set" in rendered
|
assert "LLM_DB_PASSWORD" in rendered and "not set" in rendered
|
||||||
assert "pgvector is unreachable" in rendered
|
assert "pgvector is unreachable" in rendered
|
||||||
assert "family:" in rendered
|
|
||||||
|
tables = [t for out in outputs for t in _tables_in(out)]
|
||||||
|
family_tables = [t for t in tables if "family:*" in t.text]
|
||||||
|
assert family_tables, "expected the bib 'family:*' tag table to render"
|
||||||
|
rows = {r["name"]: r["count"] for r in family_tables[0].data.to_dicts()}
|
||||||
|
assert rows.get("family:CCM", 0) > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user