File size: 3,742 Bytes
292ca6d | 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 | #!/usr/bin/env python3
"""
Test script for deployment compatibility
"""
import sys
import os
def test_basic_imports():
"""Test basic Python imports"""
print("Testing basic imports...")
try:
import flask
print(f"β Flask {flask.__version__}")
except ImportError as e:
print(f"β Flask: {e}")
return False
try:
import numpy as np
print(f"β NumPy {np.__version__}")
except ImportError as e:
print(f"β NumPy: {e}")
return False
try:
import pandas as pd
print(f"β Pandas {pd.__version__}")
except ImportError as e:
print(f"β Pandas: {e}")
return False
return True
def test_tensorflow():
"""Test TensorFlow import"""
print("\nTesting TensorFlow...")
try:
import tensorflow as tf
print(f"β TensorFlow {tf.__version__}")
return True
except ImportError as e:
print(f"β TensorFlow not available: {e}")
print(" App will run in demo mode")
return False
def test_model_predictor():
"""Test model predictor"""
print("\nTesting model predictor...")
try:
from model_predictor import EpitopePredictor
predictor = EpitopePredictor()
if predictor.model is None:
print("β Model not loaded - will use demo mode")
else:
print("β Model loaded successfully")
# Test prediction with demo sequence
test_seq = "MKLLILTCLVAVALARPKHPIKHQGLPQEVLNENLLRFFVAPFPEVFGKEKVNEL"
b_epitopes, t_epitopes = predictor.predict_epitopes(test_seq)
print(f"β Prediction test: {len(b_epitopes)} B-cell, {len(t_epitopes)} T-cell epitopes")
return True
except Exception as e:
print(f"β Model predictor failed: {e}")
return False
def test_flask_app():
"""Test Flask app creation"""
print("\nTesting Flask app...")
try:
from app import app
with app.test_client() as client:
# Test health endpoint
response = client.get('/health')
if response.status_code == 200:
print("β Health endpoint working")
else:
print(f"β Health endpoint returned {response.status_code}")
# Test main page
response = client.get('/')
if response.status_code == 200:
print("β Main page working")
else:
print(f"β Main page returned {response.status_code}")
return True
except Exception as e:
print(f"β Flask app test failed: {e}")
return False
def main():
"""Run all deployment tests"""
print("EpiPred Deployment Test")
print("=" * 30)
tests = [
("Basic Imports", test_basic_imports),
("TensorFlow", test_tensorflow),
("Model Predictor", test_model_predictor),
("Flask App", test_flask_app)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
try:
if test_func():
passed += 1
except Exception as e:
print(f"β {test_name} ERROR: {e}")
print("\n" + "=" * 30)
print(f"Results: {passed}/{total} tests passed")
if passed >= 3: # Allow TensorFlow to fail
print("π Deployment should work!")
if passed < total:
print("β Some features may be limited (demo mode)")
else:
print("β Deployment may have issues")
return passed >= 3
if __name__ == '__main__':
success = main()
sys.exit(0 if success else 1)
|