Create 98_Test_Dashboard.py
Browse files- pages/98_Test_Dashboard.py +65 -0
pages/98_Test_Dashboard.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pages/98_Test_Dashboard.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
"""Streamlit Test Dashboard for AI E-Consult V2.
|
| 4 |
+
|
| 5 |
+
Runs the internal smoke and integration tests (tests/smoke_v2.py, tests/integration_v2.py)
|
| 6 |
+
and displays their console output live within the UI.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import io
|
| 10 |
+
import sys
|
| 11 |
+
import contextlib
|
| 12 |
+
import runpy
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
import streamlit as st
|
| 16 |
+
|
| 17 |
+
st.title("🧪 Test Dashboard — AI E-Consult V2")
|
| 18 |
+
st.caption("Run smoke and integration tests directly within the Hugging Face Space.")
|
| 19 |
+
|
| 20 |
+
tests_dir = Path(__file__).resolve().parents[1] / "tests"
|
| 21 |
+
smoke_path = tests_dir / "smoke_v2.py"
|
| 22 |
+
integ_path = tests_dir / "integration_v2.py"
|
| 23 |
+
|
| 24 |
+
if not smoke_path.exists() or not integ_path.exists():
|
| 25 |
+
st.error("❌ Test files not found. Please ensure tests/smoke_v2.py and tests/integration_v2.py exist.")
|
| 26 |
+
st.stop()
|
| 27 |
+
|
| 28 |
+
st.markdown("**Available tests:**")
|
| 29 |
+
st.markdown("- `smoke_v2.py` — basic schema and module checks")
|
| 30 |
+
st.markdown("- `integration_v2.py` — module wiring and export determinism")
|
| 31 |
+
|
| 32 |
+
run_btn = st.button("▶️ Run All Tests", use_container_width=True)
|
| 33 |
+
|
| 34 |
+
output_buf = io.StringIO()
|
| 35 |
+
|
| 36 |
+
def _run_script(path: Path):
|
| 37 |
+
print(f"\n=== Running {path.name} ===")
|
| 38 |
+
try:
|
| 39 |
+
runpy.run_path(str(path), run_name="__main__")
|
| 40 |
+
except SystemExit as e:
|
| 41 |
+
print(f"Exited with code {getattr(e, 'code', '?')}")
|
| 42 |
+
except Exception as e:
|
| 43 |
+
print(f"⚠️ Error running {path.name}: {e}")
|
| 44 |
+
|
| 45 |
+
if run_btn:
|
| 46 |
+
with contextlib.redirect_stdout(output_buf), contextlib.redirect_stderr(output_buf):
|
| 47 |
+
print("🔍 Starting internal test suite...\n")
|
| 48 |
+
_run_script(smoke_path)
|
| 49 |
+
_run_script(integ_path)
|
| 50 |
+
print("\n✅ Test run completed.")
|
| 51 |
+
|
| 52 |
+
st.success("Test run completed.")
|
| 53 |
+
st.markdown("**Console Output:**")
|
| 54 |
+
st.code(output_buf.getvalue(), language="bash")
|
| 55 |
+
|
| 56 |
+
# Offer download
|
| 57 |
+
st.download_button(
|
| 58 |
+
"💾 Download Results",
|
| 59 |
+
data=output_buf.getvalue(),
|
| 60 |
+
file_name="test_results_v2.txt",
|
| 61 |
+
mime="text/plain",
|
| 62 |
+
use_container_width=True,
|
| 63 |
+
)
|
| 64 |
+
else:
|
| 65 |
+
st.info("Click 'Run All Tests' to execute internal test scripts and view results here.")
|