Spaces:
Running
Running
File size: 3,747 Bytes
5d7656c |
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 |
#!/usr/bin/env python3
"""
Simple test to verify token works directly
"""
import os
import sys
from pathlib import Path
# Add the scripts directory to the path
sys.path.append(str(Path(__file__).parent.parent / "scripts"))
def test_token_direct():
"""Test token validation directly"""
print("π Testing Token Directly")
print("=" * 50)
# Test token from user
test_token = "xxxx"
print(f"Testing token directly: {'*' * 10}...{test_token[-4:]}")
# Clear any existing environment variables
if 'HF_TOKEN' in os.environ:
del os.environ['HF_TOKEN']
if 'HUGGING_FACE_HUB_TOKEN' in os.environ:
del os.environ['HUGGING_FACE_HUB_TOKEN']
# 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_username_extraction_direct():
"""Test username extraction directly"""
print("\nπ Testing Username Extraction Directly")
print("=" * 50)
# Test token from user
test_token = "xxx"
print(f"Testing username extraction directly: {'*' * 10}...{test_token[-4:]}")
# Clear any existing environment variables
if 'HF_TOKEN' in os.environ:
del os.environ['HF_TOKEN']
if 'HUGGING_FACE_HUB_TOKEN' in os.environ:
del os.environ['HUGGING_FACE_HUB_TOKEN']
# Import the username extraction function
try:
sys.path.append(str(Path(__file__).parent.parent / "scripts" / "dataset_tonic"))
from setup_hf_dataset import get_username_from_token
print("β
Username extraction module imported successfully")
except ImportError as e:
print(f"β Failed to import username extraction 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 main():
"""Run all direct token tests"""
print("π Direct Token Testing")
print("=" * 50)
tests = [
test_token_direct,
test_username_extraction_direct
]
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 DIRECT TOKEN TESTS PASSED!")
print("β
Token validation: Working")
print("β
Username extraction: Working")
print("\nThe token works correctly when used directly!")
else:
print("β SOME DIRECT 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) |