Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	| #!/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) | 
