Spaces:
Sleeping
Sleeping
File size: 4,733 Bytes
afad319 |
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 |
#!/usr/bin/env python3
"""
Test script for HF Spaces configuration
=======================================
This script tests the HF Spaces configuration module to ensure it's working correctly.
Run this script to verify that the configuration is properly set up.
"""
import os
import sys
from pathlib import Path
def test_hf_spaces_config():
"""Test the HF Spaces configuration"""
print("π§ͺ Testing HF Spaces Configuration")
print("=" * 50)
try:
# Import the configuration
from hf_spaces_config import get_hf_config, is_hf_spaces
print("β
Successfully imported HF Spaces configuration")
# Test environment detection
print(f"\nπ Environment Detection:")
print(f" Is HF Spaces: {is_hf_spaces()}")
# Get configuration
config = get_hf_config()
print(f" Configuration loaded: {type(config).__name__}")
# Test cache directories
print(f"\nπ Cache Directories:")
for name, path in config.cache_dirs.items():
exists = os.path.exists(path)
print(f" {name}: {path} {'β
' if exists else 'β'}")
# Test environment variables
print(f"\nπ§ Environment Variables:")
env_vars = config.env_vars
for key, value in env_vars.items():
print(f" {key}: {value}")
# Test model configuration
print(f"\nπ€ Model Configuration:")
model_config = config.get_model_config()
for key, value in model_config.items():
print(f" {key}: {value}")
# Test guard rail configuration
print(f"\nπ‘οΈ Guard Rail Configuration:")
guard_config = config.get_guard_rail_config()
for key, value in guard_config.items():
print(f" {key}: {value}")
# Test resource limits
print(f"\nπ Resource Limits:")
resource_limits = config.get_resource_limits()
for key, value in resource_limits.items():
print(f" {key}: {value}")
print(f"\nβ
All tests passed!")
return True
except ImportError as e:
print(f"β Import error: {e}")
return False
except Exception as e:
print(f"β Configuration error: {e}")
return False
def test_cache_directories():
"""Test cache directory creation"""
print(f"\nπ§ Testing Cache Directory Creation")
print("=" * 50)
try:
from hf_spaces_config import get_hf_config
config = get_hf_config()
# Test directory creation
for name, path in config.cache_dirs.items():
try:
Path(path).mkdir(parents=True, exist_ok=True)
print(f"β
Created: {name} -> {path}")
except Exception as e:
print(f"β Failed to create {name}: {e}")
return True
except Exception as e:
print(f"β Cache directory test failed: {e}")
return False
def test_environment_variables():
"""Test environment variable setup"""
print(f"\nπ§ Testing Environment Variables")
print("=" * 50)
try:
from hf_spaces_config import get_hf_config
config = get_hf_config()
# Check if environment variables are set
for key, expected_value in config.env_vars.items():
actual_value = os.environ.get(key, "NOT_SET")
status = "β
" if actual_value == expected_value else "β"
print(f" {key}: {actual_value} {status}")
return True
except Exception as e:
print(f"β Environment variable test failed: {e}")
return False
def main():
"""Run all tests"""
print("π HF Spaces Configuration Test Suite")
print("=" * 60)
tests = [
("Configuration Import", test_hf_spaces_config),
("Cache Directories", test_cache_directories),
("Environment Variables", test_environment_variables),
]
results = []
for test_name, test_func in tests:
print(f"\nπ§ͺ Running: {test_name}")
result = test_func()
results.append((test_name, result))
# Summary
print(f"\nπ Test Summary")
print("=" * 30)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "β
PASS" if result else "β FAIL"
print(f" {test_name}: {status}")
print(f"\nOverall: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! HF Spaces configuration is working correctly.")
return 0
else:
print("β οΈ Some tests failed. Please check the configuration.")
return 1
if __name__ == "__main__":
sys.exit(main())
|