File size: 3,867 Bytes
bd3da01 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
#!/usr/bin/env python3
"""
Test script for Hugging Face Spaces deployment
Verifies that the app.py works correctly without external dependencies
"""
import sys
import os
import importlib.util
def test_imports():
"""Test that all required imports work"""
print("Testing imports...")
required_packages = [
'streamlit',
'numpy',
'pandas',
'time',
'threading',
'json',
'logging',
'datetime',
'random'
]
for package in required_packages:
try:
importlib.import_module(package)
print(f"β
{package}")
except ImportError as e:
print(f"β {package}: {e}")
return False
return True
def test_app_structure():
"""Test that app.py has the required structure"""
print("\nTesting app.py structure...")
if not os.path.exists('app.py'):
print("β app.py not found")
return False
with open('app.py', 'r') as f:
content = f.read()
required_components = [
'SimulatedFederatedSystem',
'ClientSimulator',
'st.set_page_config',
'st.title',
'st.sidebar',
'st.header',
'st.form'
]
for component in required_components:
if component in content:
print(f"β
{component}")
else:
print(f"β {component} not found")
return False
return True
def test_requirements():
"""Test that requirements.txt is minimal"""
print("\nTesting requirements.txt...")
if not os.path.exists('requirements.txt'):
print("β requirements.txt not found")
return False
with open('requirements.txt', 'r') as f:
requirements = f.read()
# Check for minimal dependencies
minimal_deps = ['streamlit', 'numpy', 'pandas']
heavy_deps = ['tensorflow', 'torch', 'scikit-learn', 'flask', 'fastapi']
for dep in minimal_deps:
if dep in requirements:
print(f"β
{dep}")
else:
print(f"β {dep} missing")
return False
for dep in heavy_deps:
if dep in requirements:
print(f"β οΈ {dep} found (may cause HF Spaces issues)")
return True
def test_readme():
"""Test that README.md has HF Spaces config"""
print("\nTesting README.md...")
if not os.path.exists('README.md'):
print("β README.md not found")
return False
with open('README.md', 'r') as f:
content = f.read()
required_config = [
'title: Federated Credit Scoring',
'sdk: streamlit',
'app_port: 8501'
]
for config in required_config:
if config in content:
print(f"β
{config}")
else:
print(f"β {config} not found")
return False
return True
def main():
"""Run all tests"""
print("π§ͺ Testing Hugging Face Spaces Deployment")
print("=" * 50)
tests = [
test_imports,
test_app_structure,
test_requirements,
test_readme
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
else:
print(f"β Test failed: {test.__name__}")
except Exception as e:
print(f"β Test error: {test.__name__} - {e}")
print("\n" + "=" * 50)
print(f"Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! Ready for HF Spaces deployment.")
return True
else:
print("β Some tests failed. Please fix issues before deployment.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |