Spaces:
Running
Running
File size: 6,791 Bytes
2da5c04 |
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
#!/usr/bin/env python3
"""
Test script to verify Trackio deployment fixes
"""
import os
import sys
import subprocess
from pathlib import Path
def test_imports():
"""Test that required packages are available"""
print("π Testing imports...")
try:
from huggingface_hub import HfApi, create_repo, upload_file
print("β
huggingface_hub imports successful")
except ImportError as e:
print(f"β huggingface_hub import failed: {e}")
return False
try:
from datasets import Dataset
print("β
datasets import successful")
except ImportError as e:
print(f"β datasets import failed: {e}")
return False
return True
def test_script_exists(script_path):
"""Test that a script exists and is executable"""
path = Path(script_path)
if not path.exists():
print(f"β Script not found: {script_path}")
return False
if not path.is_file():
print(f"β Not a file: {script_path}")
return False
print(f"β
Script exists: {script_path}")
return True
def test_script_syntax(script_path):
"""Test that a script has valid Python syntax"""
try:
with open(script_path, 'r', encoding='utf-8') as f:
compile(f.read(), script_path, 'exec')
print(f"β
Syntax valid: {script_path}")
return True
except SyntaxError as e:
print(f"β Syntax error in {script_path}: {e}")
return False
except Exception as e:
print(f"β Error reading {script_path}: {e}")
return False
def test_environment_variables():
"""Test that required environment variables are set"""
print("π Testing environment variables...")
hf_token = os.environ.get('HF_TOKEN')
if hf_token:
print("β
HF_TOKEN is set")
else:
print("β οΈ HF_TOKEN is not set (this is normal for testing)")
dataset_repo = os.environ.get('TRACKIO_DATASET_REPO', 'tonic/trackio-experiments')
print(f"π TRACKIO_DATASET_REPO: {dataset_repo}")
return True
def test_api_connection():
"""Test HF API connection if token is available"""
hf_token = os.environ.get('HF_TOKEN')
if not hf_token:
print("β οΈ Skipping API connection test - no HF_TOKEN")
return True
try:
from huggingface_hub import HfApi
api = HfApi(token=hf_token)
# Test basic API call
user_info = api.whoami()
print(f"β
API connection successful - User: {user_info.get('name', 'Unknown')}")
return True
except Exception as e:
print(f"β API connection failed: {e}")
return False
def test_script_functions():
"""Test that scripts can be imported and have required functions"""
print("π Testing script functions...")
# Test deploy script
try:
sys.path.append(str(Path(__file__).parent.parent / "scripts" / "trackio_tonic"))
from deploy_trackio_space import TrackioSpaceDeployer
print("β
TrackioSpaceDeployer class imported successfully")
except Exception as e:
print(f"β Failed to import TrackioSpaceDeployer: {e}")
return False
# Test dataset script
try:
sys.path.append(str(Path(__file__).parent.parent / "scripts" / "dataset_tonic"))
import setup_hf_dataset
print("β
setup_hf_dataset module imported successfully")
except Exception as e:
print(f"β Failed to import setup_hf_dataset: {e}")
return False
# Test configure script
try:
sys.path.append(str(Path(__file__).parent.parent / "scripts" / "trackio_tonic"))
import configure_trackio
print("β
configure_trackio module imported successfully")
except Exception as e:
print(f"β Failed to import configure_trackio: {e}")
return False
return True
def test_template_files():
"""Test that template files exist"""
print("π Testing template files...")
project_root = Path(__file__).parent.parent
templates_dir = project_root / "templates"
required_files = [
"spaces/app.py",
"spaces/requirements.txt",
"spaces/README.md",
"datasets/readme.md"
]
all_exist = True
for file_path in required_files:
full_path = templates_dir / file_path
if full_path.exists():
print(f"β
Template exists: {file_path}")
else:
print(f"β Template missing: {file_path}")
all_exist = False
return all_exist
def main():
"""Run all tests"""
print("π§ͺ Testing Trackio Deployment Fixes")
print("=" * 40)
tests = [
("Import Tests", test_imports),
("Script Existence", lambda: all([
test_script_exists("scripts/trackio_tonic/deploy_trackio_space.py"),
test_script_exists("scripts/dataset_tonic/setup_hf_dataset.py"),
test_script_exists("scripts/trackio_tonic/configure_trackio.py"),
test_script_exists("scripts/model_tonic/push_to_huggingface.py")
])),
("Script Syntax", lambda: all([
test_script_syntax("scripts/trackio_tonic/deploy_trackio_space.py"),
test_script_syntax("scripts/dataset_tonic/setup_hf_dataset.py"),
test_script_syntax("scripts/trackio_tonic/configure_trackio.py"),
test_script_syntax("scripts/model_tonic/push_to_huggingface.py")
])),
("Environment Variables", test_environment_variables),
("API Connection", test_api_connection),
("Script Functions", test_script_functions),
("Template Files", test_template_files)
]
results = []
for test_name, test_func in tests:
print(f"\nπ {test_name}")
print("-" * 20)
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"β Test failed with exception: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 40)
print("π Test Results Summary")
print("=" * 40)
passed = 0
total = len(results)
for test_name, result in results:
status = "β
PASS" if result else "β FAIL"
print(f"{status}: {test_name}")
if result:
passed += 1
print(f"\nπ― Overall: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! The fixes are working correctly.")
return True
else:
print("β οΈ Some tests failed. Please check the issues above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |