Spaces:
Sleeping
Sleeping
Evgueni Poloukarov
commited on
Commit
·
6ab2f4a
1
Parent(s):
330e408
feat: add automated notebook test runner
Browse files- test_runner.py +98 -0
test_runner.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test runner for FBMC notebooks on HuggingFace Space
|
| 4 |
+
Executes notebooks and reports results
|
| 5 |
+
"""
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
|
| 12 |
+
def run_notebook(notebook_path, timeout=600):
|
| 13 |
+
"""Execute a Jupyter notebook and return success status"""
|
| 14 |
+
print(f"\n{'='*60}")
|
| 15 |
+
print(f"Running: {notebook_path.name}")
|
| 16 |
+
print(f"Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
| 17 |
+
print(f"{'='*60}\n")
|
| 18 |
+
|
| 19 |
+
cmd = [
|
| 20 |
+
"jupyter", "nbconvert",
|
| 21 |
+
"--to", "notebook",
|
| 22 |
+
"--execute",
|
| 23 |
+
"--inplace",
|
| 24 |
+
f"--ExecutePreprocessor.timeout={timeout}",
|
| 25 |
+
str(notebook_path)
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout+60)
|
| 30 |
+
|
| 31 |
+
if result.returncode == 0:
|
| 32 |
+
print(f"\n✅ SUCCESS: {notebook_path.name}")
|
| 33 |
+
return True
|
| 34 |
+
else:
|
| 35 |
+
print(f"\n❌ FAILED: {notebook_path.name}")
|
| 36 |
+
print(f"Error: {result.stderr}")
|
| 37 |
+
return False
|
| 38 |
+
except subprocess.TimeoutExpired:
|
| 39 |
+
print(f"\n❌ TIMEOUT: {notebook_path.name} exceeded {timeout}s")
|
| 40 |
+
return False
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"\n❌ ERROR: {str(e)}")
|
| 43 |
+
return False
|
| 44 |
+
|
| 45 |
+
def main():
|
| 46 |
+
# Check environment
|
| 47 |
+
if "HF_TOKEN" not in os.environ:
|
| 48 |
+
print("⚠️ Warning: HF_TOKEN not set!")
|
| 49 |
+
print(" Set with: export HF_TOKEN='your_token'\n")
|
| 50 |
+
|
| 51 |
+
# Check GPU
|
| 52 |
+
try:
|
| 53 |
+
import torch
|
| 54 |
+
print(f"GPU Available: {torch.cuda.is_available()}")
|
| 55 |
+
if torch.cuda.is_available():
|
| 56 |
+
print(f"GPU Name: {torch.cuda.get_device_name(0)}")
|
| 57 |
+
print(f"GPU Memory: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f} GB")
|
| 58 |
+
except ImportError:
|
| 59 |
+
print("⚠️ PyTorch not installed")
|
| 60 |
+
|
| 61 |
+
print("\n")
|
| 62 |
+
|
| 63 |
+
# Define test sequence
|
| 64 |
+
tests = [
|
| 65 |
+
("/data/inference_smoke_test.ipynb", 300), # 5 min
|
| 66 |
+
# Uncomment to run full tests:
|
| 67 |
+
# ("/data/inference_full_14day.ipynb", 900), # 15 min
|
| 68 |
+
# ("/data/evaluation.ipynb", 300), # 5 min
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
results = {}
|
| 72 |
+
|
| 73 |
+
for notebook_path, timeout in tests:
|
| 74 |
+
nb_path = Path(notebook_path)
|
| 75 |
+
if not nb_path.exists():
|
| 76 |
+
print(f"❌ Not found: {notebook_path}")
|
| 77 |
+
results[nb_path.name] = False
|
| 78 |
+
continue
|
| 79 |
+
|
| 80 |
+
success = run_notebook(nb_path, timeout)
|
| 81 |
+
results[nb_path.name] = success
|
| 82 |
+
|
| 83 |
+
# Summary
|
| 84 |
+
print(f"\n{'='*60}")
|
| 85 |
+
print("SUMMARY")
|
| 86 |
+
print(f"{'='*60}")
|
| 87 |
+
for name, success in results.items():
|
| 88 |
+
status = "✅ PASS" if success else "❌ FAIL"
|
| 89 |
+
print(f"{status}: {name}")
|
| 90 |
+
|
| 91 |
+
total = len(results)
|
| 92 |
+
passed = sum(results.values())
|
| 93 |
+
print(f"\nResults: {passed}/{total} passed")
|
| 94 |
+
|
| 95 |
+
return 0 if all(results.values()) else 1
|
| 96 |
+
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
sys.exit(main())
|