Spaces:
Running
Running
File size: 5,581 Bytes
93ed7a1 75bcdb3 93ed7a1 75bcdb3 93ed7a1 |
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
#!/usr/bin/env python3
"""
Test script to verify deployment scripts work correctly
"""
import os
import sys
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
def test_templates_exist():
"""Test that all required template files exist"""
print("π Testing template files...")
# Check spaces templates
spaces_dir = project_root / "templates" / "spaces"
demo_types = ["demo_smol", "demo_gpt", "trackio"]
spaces_files = ["app.py", "requirements.txt", "README.md"]
for demo_type in demo_types:
demo_dir = spaces_dir / demo_type
print(f"Checking {demo_type} templates...")
for file_name in spaces_files:
file_path = demo_dir / file_name
if file_path.exists():
print(f"β
{file_path}")
else:
print(f"β {file_path} not found")
return False
# Check datasets templates
datasets_dir = project_root / "templates" / "datasets"
datasets_files = ["readme.md"]
for file_name in datasets_files:
file_path = datasets_dir / file_name
if file_path.exists():
print(f"β
{file_path}")
else:
print(f"β {file_path} not found")
return False
return True
def test_deployment_scripts():
"""Test that deployment scripts can import required modules"""
print("\nπ Testing deployment scripts...")
try:
# Test space deployment script
from scripts.trackio_tonic.deploy_trackio_space import TrackioSpaceDeployer
print("β
deploy_trackio_space.py imports successfully")
# Test dataset setup script
from scripts.dataset_tonic.setup_hf_dataset import setup_trackio_dataset
print("β
setup_hf_dataset.py imports successfully")
return True
except Exception as e:
print(f"β Deployment script test failed: {e}")
return False
def test_file_copying():
"""Test that file copying logic works"""
print("\nπ Testing file copying logic...")
try:
# Test space deployment file copying
from scripts.trackio_tonic.deploy_trackio_space import TrackioSpaceDeployer
# Create a mock deployer
deployer = TrackioSpaceDeployer("test-space", "test-user", "test-token")
# Test that templates directory exists
project_root = Path(__file__).parent
templates_dir = project_root / "templates" / "spaces"
if templates_dir.exists():
print(f"β
Templates directory exists: {templates_dir}")
# Check that required files exist
for file_name in ["app.py", "requirements.txt", "README.md"]:
file_path = templates_dir / file_name
if file_path.exists():
print(f"β
Template file exists: {file_path}")
else:
print(f"β Template file missing: {file_path}")
return False
else:
print(f"β Templates directory missing: {templates_dir}")
return False
return True
except Exception as e:
print(f"β File copying test failed: {e}")
return False
def test_readme_inclusion():
"""Test that README inclusion logic works"""
print("\nπ Testing README inclusion...")
try:
# Test dataset README inclusion
from scripts.dataset_tonic.setup_hf_dataset import setup_trackio_dataset
# Check that README template exists
project_root = Path(__file__).parent
readme_path = project_root / "templates" / "datasets" / "readme.md"
if readme_path.exists():
print(f"β
README template exists: {readme_path}")
# Check README content
with open(readme_path, 'r', encoding='utf-8') as f:
content = f.read()
if len(content.strip()) > 0:
print(f"β
README has content ({len(content)} characters)")
else:
print(f"β οΈ README is empty")
else:
print(f"β README template missing: {readme_path}")
return False
return True
except Exception as e:
print(f"β README inclusion test failed: {e}")
return False
def main():
"""Run all tests"""
print("π Testing Deployment Scripts")
print("=" * 50)
tests = [
test_templates_exist,
test_deployment_scripts,
test_file_copying,
test_readme_inclusion
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
else:
print(f"β Test failed: {test.__name__}")
print(f"\n{'='*50}")
print(f"π Test Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! Deployment scripts are ready to use.")
print("\nπ Deployment workflow:")
print("1. Space deployment will copy files from templates/spaces/")
print("2. Dataset creation will include README from templates/datasets/")
print("3. Both scripts will properly upload all required files")
return 0
else:
print("β Some tests failed. Please fix the issues before deployment.")
return 1
if __name__ == "__main__":
exit(main()) |