import sys, tempfile, unittest from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from okf_viz import build_graph, render_html, main FIX = Path(__file__).resolve().parent / "fixtures" / "mini_bundle" class TestViz(unittest.TestCase): def test_build_graph_nodes_and_edges(self): g = build_graph(FIX) ids = {n["id"] for n in g["nodes"]} self.assertIn("tables/orders", ids) self.assertTrue(any(e["source"] == "tables/orders" and e["target"] == "tables/customers" for e in g["edges"])) def test_render_html_embeds_data_and_cdn(self): html = render_html(build_graph(FIX), "Mini") self.assertIn("cytoscape", html) self.assertIn('"nodes"', html) def test_render_html_escapes_script_close(self): g = {"nodes": [{"id": "x", "type": "T", "title": "x", "description": "", "body": "hi"}], "edges": []} html = render_html(g, "X") self.assertNotIn("hi", html) def test_main_writes_file(self): with tempfile.TemporaryDirectory() as d: out = Path(d) / "v.html" self.assertEqual(main(["--bundle", str(FIX), "--out", str(out)]), 0) self.assertTrue(out.exists() and out.stat().st_size > 500) if __name__ == "__main__": unittest.main()