Spaces:
Running
Running
#!/usr/bin/env python3 | |
""" | |
Phase 6 Deployment Readiness Test | |
Comprehensive validation that all improvements are ready for HuggingFace deployment. | |
""" | |
import sys | |
import os | |
from pathlib import Path | |
import importlib.util | |
# Add current directory to path | |
sys.path.insert(0, str(Path(__file__).parent)) | |
def test_core_components(): | |
"""Test that all core components are available.""" | |
print("π Testing Core Components...") | |
# Test agent imports | |
try: | |
from agents.fixed_enhanced_unified_agno_agent import FixedGAIAAgent | |
print("β Fixed GAIA Agent import successful") | |
except ImportError as e: | |
print(f"β Fixed GAIA Agent import failed: {e}") | |
return False | |
# Test calculator prompt enhancer | |
try: | |
from utils.calculator_prompt_enhancer import CalculatorPromptEnhancer | |
print("β Calculator Prompt Enhancer import successful") | |
except ImportError as e: | |
print(f"β Calculator Prompt Enhancer import failed: {e}") | |
return False | |
# Test response processor | |
try: | |
from utils.response_processor import EnhancedResponseProcessor | |
print("β Enhanced Response Processor import successful") | |
except ImportError as e: | |
print(f"β Enhanced Response Processor import failed: {e}") | |
return False | |
# Test file handler | |
try: | |
from utils.file_handler import EnhancedFileHandler | |
print("β Enhanced File Handler import successful") | |
except ImportError as e: | |
print(f"β Enhanced File Handler import failed: {e}") | |
return False | |
return True | |
def test_app_functionality(): | |
"""Test that the main app.py is functional.""" | |
print("\nπ Testing App Functionality...") | |
try: | |
# Test app import | |
spec = importlib.util.spec_from_file_location("app", "app.py") | |
app_module = importlib.util.module_from_spec(spec) | |
# Check if app has required functions | |
spec.loader.exec_module(app_module) | |
if hasattr(app_module, 'setup_environment'): | |
print("β App has setup_environment function") | |
elif hasattr(app_module, 'DeploymentReadyGAIAAgent'): | |
print("β App has DeploymentReadyGAIAAgent class") | |
else: | |
print("β App missing required components") | |
return False | |
return True | |
except Exception as e: | |
print(f"β App functionality test failed: {e}") | |
return False | |
def test_calculator_improvements(): | |
"""Test that calculator improvements are working.""" | |
print("\nπ Testing Calculator Improvements...") | |
try: | |
from utils.calculator_prompt_enhancer import CalculatorPromptEnhancer | |
enhancer = CalculatorPromptEnhancer() | |
# Test exponentiation detection | |
test_cases = [ | |
"What is 2 to the power of 8?", | |
"Calculate 2^8", | |
"What is 2**8?" | |
] | |
for test_case in test_cases: | |
enhanced = enhancer.enhance_prompt_for_exponentiation(test_case) | |
if "Python" in enhanced or "python" in enhanced: | |
print(f"β Exponentiation enhancement working: {test_case}") | |
else: | |
print(f"β οΈ Enhancement may not be working: {test_case}") | |
return True | |
except Exception as e: | |
print(f"β Calculator improvements test failed: {e}") | |
return False | |
def test_file_structure(): | |
"""Test that all required files are present.""" | |
print("\nπ Testing File Structure...") | |
required_files = [ | |
"app.py", | |
"requirements.txt", | |
"push_to_hf.py", | |
"agents/fixed_enhanced_unified_agno_agent.py", | |
"utils/calculator_prompt_enhancer.py", | |
"utils/response_processor.py", | |
"utils/file_handler.py", | |
"utils/environment_setup.py" | |
] | |
missing_files = [] | |
for file_path in required_files: | |
if Path(file_path).exists(): | |
print(f"β {file_path}") | |
else: | |
print(f"β Missing: {file_path}") | |
missing_files.append(file_path) | |
return len(missing_files) == 0 | |
def test_phase_improvements(): | |
"""Test that all phase improvements are integrated.""" | |
print("\nπ Testing Phase Improvements Integration...") | |
# Check Phase 1-5 test results | |
test_files = [ | |
"tests/test_calculator_accuracy_100.py", | |
"tests/test_calculator_exponentiation_fix.py", | |
"tests/test_agent_prompt_enhancer_integration.py", | |
"tests/test_response_processor.py", | |
"tests/test_file_handler.py" | |
] | |
available_tests = [] | |
for test_file in test_files: | |
if Path(test_file).exists(): | |
print(f"β {test_file}") | |
available_tests.append(test_file) | |
else: | |
print(f"β οΈ Test not found: {test_file}") | |
print(f"π Available test suites: {len(available_tests)}/{len(test_files)}") | |
return len(available_tests) >= 3 # At least 3 test suites should be available | |
def test_deployment_script(): | |
"""Test that deployment script is ready.""" | |
print("\nπ Testing Deployment Script...") | |
try: | |
from push_to_hf import push_to_huggingface | |
print("β HuggingFace deployment script import successful") | |
# Check if script has proper error handling | |
if "HF_TOKEN" in open("push_to_hf.py").read(): | |
print("β Deployment script checks for HF_TOKEN") | |
else: | |
print("β Deployment script missing HF_TOKEN check") | |
return False | |
return True | |
except Exception as e: | |
print(f"β Deployment script test failed: {e}") | |
return False | |
def main(): | |
"""Run comprehensive deployment readiness test.""" | |
print("π Phase 6 Deployment Readiness Test") | |
print("=" * 50) | |
tests = [ | |
("Core Components", test_core_components), | |
("App Functionality", test_app_functionality), | |
("Calculator Improvements", test_calculator_improvements), | |
("File Structure", test_file_structure), | |
("Phase Improvements", test_phase_improvements), | |
("Deployment Script", test_deployment_script) | |
] | |
passed_tests = 0 | |
total_tests = len(tests) | |
for test_name, test_func in tests: | |
try: | |
if test_func(): | |
passed_tests += 1 | |
print(f"β {test_name}: PASSED") | |
else: | |
print(f"β {test_name}: FAILED") | |
except Exception as e: | |
print(f"β {test_name}: ERROR - {e}") | |
print("\n" + "=" * 50) | |
print(f"π Test Results: {passed_tests}/{total_tests} tests passed") | |
if passed_tests == total_tests: | |
print("π DEPLOYMENT READY! All tests passed.") | |
print("π Ready to push to HuggingFace Space with:") | |
print(" cd deployment-ready && python push_to_hf.py") | |
return True | |
else: | |
print("β οΈ Some tests failed. Please review before deployment.") | |
return False | |
if __name__ == "__main__": | |
success = main() | |
sys.exit(0 if success else 1) |