#!/usr/bin/env python3 """ Test script for deployment components verification Tests Trackio Space deployment and model repository deployment components """ import os import sys import json from pathlib import Path def test_trackio_space_components(): """Test Trackio Space deployment components""" print("šŸ” Testing Trackio Space Deployment Components") print("=" * 50) # Test 1: Check if deployment script exists deploy_script = Path("scripts/trackio_tonic/deploy_trackio_space.py") if deploy_script.exists(): print("āœ… Trackio Space deployment script exists") else: print("āŒ Trackio Space deployment script missing") return False # Test 2: Check if app.py template exists app_template = Path("templates/spaces/app.py") if app_template.exists(): print("āœ… Gradio app template exists") # Check if it has required components with open(app_template, 'r', encoding='utf-8') as f: content = f.read() if "class TrackioSpace" in content: print("āœ… TrackioSpace class implemented") else: print("āŒ TrackioSpace class missing") return False if "def create_experiment" in content: print("āœ… Experiment creation functionality") else: print("āŒ Experiment creation missing") return False if "def log_metrics" in content: print("āœ… Metrics logging functionality") else: print("āŒ Metrics logging missing") return False if "def get_experiment" in content: print("āœ… Experiment retrieval functionality") else: print("āŒ Experiment retrieval missing") return False else: print("āŒ Gradio app template missing") return False # Test 3: Check if requirements.txt exists requirements = Path("templates/spaces/requirements.txt") if requirements.exists(): print("āœ… Space requirements file exists") # Check for required dependencies with open(requirements, 'r', encoding='utf-8') as f: content = f.read() required_deps = ['gradio', 'pandas', 'plotly', 'datasets', 'huggingface-hub'] for dep in required_deps: if dep in content: print(f"āœ… Required dependency: {dep}") else: print(f"āŒ Missing dependency: {dep}") return False else: print("āŒ Space requirements file missing") return False # Test 4: Check if README template exists readme_template = Path("templates/spaces/README.md") if readme_template.exists(): print("āœ… Space README template exists") # Check for required metadata with open(readme_template, 'r', encoding='utf-8') as f: content = f.read() if "title:" in content and "sdk: gradio" in content: print("āœ… HF Spaces metadata present") else: print("āŒ HF Spaces metadata missing") return False else: print("āŒ Space README template missing") return False print("āœ… All Trackio Space components verified!") return True def test_model_repository_components(): """Test model repository deployment components""" print("\nšŸ” Testing Model Repository Deployment Components") print("=" * 50) # Test 1: Check if push script exists push_script = Path("scripts/model_tonic/push_to_huggingface.py") if push_script.exists(): print("āœ… Model push script exists") else: print("āŒ Model push script missing") return False # Test 2: Check if quantize script exists quantize_script = Path("scripts/model_tonic/quantize_model.py") if quantize_script.exists(): print("āœ… Model quantization script exists") else: print("āŒ Model quantization script missing") return False # Test 3: Check if model card template exists model_card_template = Path("templates/model_card.md") if model_card_template.exists(): print("āœ… Model card template exists") # Check for required sections with open(model_card_template, 'r', encoding='utf-8') as f: content = f.read() required_sections = ['base_model:', 'pipeline_tag:', 'tags:'] for section in required_sections: if section in content: print(f"āœ… Required section: {section}") else: print(f"āŒ Missing section: {section}") return False else: print("āŒ Model card template missing") return False # Test 4: Check if model card generator exists card_generator = Path("scripts/model_tonic/generate_model_card.py") if card_generator.exists(): print("āœ… Model card generator exists") else: print("āŒ Model card generator missing") return False # Test 5: Check push script functionality with open(push_script, 'r', encoding='utf-8') as f: content = f.read() required_functions = [ 'def create_repository', 'def upload_model_files', 'def create_model_card', 'def validate_model_path' ] for func in required_functions: if func in content: print(f"āœ… Required function: {func}") else: print(f"āŒ Missing function: {func}") return False print("āœ… All Model Repository components verified!") return True def test_integration_components(): """Test integration between components""" print("\nšŸ” Testing Integration Components") print("=" * 50) # Test 1: Check if launch script integrates deployment launch_script = Path("launch.sh") if launch_script.exists(): print("āœ… Launch script exists") with open(launch_script, 'r', encoding='utf-8') as f: content = f.read() if "deploy_trackio_space.py" in content: print("āœ… Trackio Space deployment integrated") else: print("āŒ Trackio Space deployment not integrated") return False if "push_to_huggingface.py" in content: print("āœ… Model push integrated") else: print("āŒ Model push not integrated") return False else: print("āŒ Launch script missing") return False # Test 2: Check if monitoring integration exists monitoring_script = Path("src/monitoring.py") if monitoring_script.exists(): print("āœ… Monitoring script exists") with open(monitoring_script, 'r', encoding='utf-8') as f: content = f.read() if "class SmolLM3Monitor" in content: print("āœ… SmolLM3Monitor class implemented") else: print("āŒ SmolLM3Monitor class missing") return False else: print("āŒ Monitoring script missing") return False # Test 3: Check if dataset integration exists dataset_script = Path("scripts/dataset_tonic/setup_hf_dataset.py") if dataset_script.exists(): print("āœ… Dataset setup script exists") with open(dataset_script, 'r', encoding='utf-8') as f: content = f.read() if "def setup_trackio_dataset" in content: print("āœ… Dataset setup function implemented") else: print("āŒ Dataset setup function missing") return False else: print("āŒ Dataset setup script missing") return False print("āœ… All integration components verified!") return True def test_token_validation(): """Test token validation functionality""" print("\nšŸ” Testing Token Validation") print("=" * 50) # Test 1: Check if validation script exists validation_script = Path("scripts/validate_hf_token.py") if validation_script.exists(): print("āœ… Token validation script exists") with open(validation_script, 'r', encoding='utf-8') as f: content = f.read() if "def validate_hf_token" in content: print("āœ… Token validation function implemented") else: print("āŒ Token validation function missing") return False else: print("āŒ Token validation script missing") return False print("āœ… Token validation components verified!") return True def main(): """Run all component tests""" print("šŸš€ Deployment Components Verification") print("=" * 50) tests = [ test_trackio_space_components, test_model_repository_components, test_integration_components, test_token_validation ] all_passed = True for test in tests: try: if not test(): all_passed = False except Exception as e: print(f"āŒ Test failed with error: {e}") all_passed = False print("\n" + "=" * 50) if all_passed: print("šŸŽ‰ ALL COMPONENTS VERIFIED SUCCESSFULLY!") print("āœ… Trackio Space deployment components: Complete") print("āœ… Model repository deployment components: Complete") print("āœ… Integration components: Complete") print("āœ… Token validation components: Complete") print("\nAll important deployment components are properly implemented!") else: print("āŒ SOME COMPONENTS NEED ATTENTION!") print("Please check the failed components above.") return all_passed if __name__ == "__main__": success = main() sys.exit(0 if success else 1)