Spaces:
Running
Running
File size: 4,730 Bytes
fd0524b 5d7656c fd0524b 5d7656c fd0524b 5d7656c fd0524b |
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 |
#!/usr/bin/env python3
"""
Test script to verify token validation works with the provided token
"""
import os
import sys
import json
from pathlib import Path
# Add the scripts directory to the path
sys.path.append(str(Path(__file__).parent.parent / "scripts"))
def test_token_validation():
"""Test token validation with the provided token"""
print("π Testing Token Validation")
print("=" * 50)
# Test token from user
test_token = "xxx"
print(f"Testing token: {'*' * 10}...{test_token[-4:]}")
# Import the validation function
try:
from validate_hf_token import validate_hf_token
print("β
Token validation module imported successfully")
except ImportError as e:
print(f"β Failed to import token validation module: {e}")
return False
# Test token validation
try:
success, username, error = validate_hf_token(test_token)
if success:
print(f"β
Token validation successful!")
print(f"β
Username: {username}")
return True
else:
print(f"β Token validation failed: {error}")
return False
except Exception as e:
print(f"β Token validation error: {e}")
return False
def test_dataset_setup():
"""Test dataset setup with the provided token"""
print("\nπ Testing Dataset Setup")
print("=" * 50)
# Test token from user
test_token = "xxxx"
print(f"Testing dataset setup with token: {'*' * 10}...{test_token[-4:]}")
# Set environment variable
os.environ['HUGGING_FACE_HUB_TOKEN'] = test_token
os.environ['HF_TOKEN'] = test_token
# Import the dataset setup function
try:
sys.path.append(str(Path(__file__).parent.parent / "scripts" / "dataset_tonic"))
from setup_hf_dataset import get_username_from_token
print("β
Dataset setup module imported successfully")
except ImportError as e:
print(f"β Failed to import dataset setup module: {e}")
return False
# Test username extraction
try:
username = get_username_from_token(test_token)
if username:
print(f"β
Username extraction successful: {username}")
return True
else:
print(f"β Username extraction failed")
return False
except Exception as e:
print(f"β Username extraction error: {e}")
return False
def test_space_deployment():
"""Test space deployment with the provided token"""
print("\nπ Testing Space Deployment")
print("=" * 50)
# Test token from user
test_token = "xxxx"
print(f"Testing space deployment with token: {'*' * 10}...{test_token[-4:]}")
# Import the space deployment class
try:
sys.path.append(str(Path(__file__).parent.parent / "scripts" / "trackio_tonic"))
from deploy_trackio_space import TrackioSpaceDeployer
print("β
Space deployment module imported successfully")
except ImportError as e:
print(f"β Failed to import space deployment module: {e}")
return False
# Test deployer initialization
try:
deployer = TrackioSpaceDeployer("test-space", test_token)
if deployer.username:
print(f"β
Space deployer initialization successful")
print(f"β
Username: {deployer.username}")
return True
else:
print(f"β Space deployer initialization failed")
return False
except Exception as e:
print(f"β Space deployer initialization error: {e}")
return False
def main():
"""Run all token tests"""
print("π Token Validation and Deployment Tests")
print("=" * 50)
tests = [
test_token_validation,
test_dataset_setup,
test_space_deployment
]
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 TOKEN TESTS PASSED!")
print("β
Token validation: Working")
print("β
Dataset setup: Working")
print("β
Space deployment: Working")
print("\nThe token is working correctly with all components!")
else:
print("β SOME TOKEN TESTS FAILED!")
print("Please check the failed tests above.")
return all_passed
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |