CoolFace
Apppublic

ani-sdhu/essp

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
test_app.py65 linesDownload Raw Back to root
1#!/usr/bin/env python32"""Offline test for app.py: import guard, landing gate, and the launch swap.3No network or keys required (key validation is stubbed)."""4import app                            # sets EDD_IMPORT_ONLY, then imports dashboard5import energy_data_dashboard as edd   # already loaded (guarded) by the line above6 7 8def run():9    fails = []10    def check(name, cond):11        print(("PASS" if cond else "FAIL"), "-", name)12        if not cond:13            fails.append(name)14 15    # The imported dashboard module must NOT have registered its own page.16    check("import guard prevents dashboard self-serve",17          not hasattr(edd, "dashboard"))18 19    gate = app.create_app()20    check("gate is a FastListTemplate",21          gate.__class__.__name__ == "FastListTemplate")22    refs = gate._refs23 24    # Keys are entered through masked password fields, and Groq is not asked for.25    check("EIA field is a PasswordInput",26          refs["eia"].__class__.__name__ == "PasswordInput")27    check("FRED field is a PasswordInput",28          refs["fred"].__class__.__name__ == "PasswordInput")29 30    # Empty keys -> prompt, no swap.31    refs["eia"].value = ""32    refs["fred"].value = ""33    refs["on_launch"]()34    check("empty keys prompt for both", "both" in (refs["msg"].object or "").lower())35    check("no swap yet (landing still in main)",36          "app-shell" not in (getattr(gate.main[0], "css_classes", []) or []))37 38    # Valid keys (validation stubbed) -> swap to the dashboard views.39    app.validate_keys = lambda e, f: []40    refs["eia"].value = "E" * 4041    refs["fred"].value = "F" * 3242    refs["on_launch"]()43    check("dashboard swapped into main",44          "app-shell" in (getattr(gate.main[0], "css_classes", []) or []))45    check("dashboard sidebar present after launch", len(gate.sidebar) == 1)46 47    # Whole gated page renders into a Bokeh document.48    try:49        from bokeh.document import Document50        app.create_app().server_doc(Document())51        built = True52    except Exception as exc:53        built = False54        print("   render error:", exc)55    check("gated page builds into a Bokeh document", built)56 57    print()58    if fails:59        print(f"{len(fails)} FAILED: {fails}"); return 160    print("ALL TESTS PASSED"); return 061 62 63if __name__ == "__main__":64    raise SystemExit(run())65