Spaces:
Running
Running
File size: 5,625 Bytes
9ad9eac |
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 |
#!/usr/bin/env python3
"""Test script for ChatUI Helper application"""
import sys
import json
from pathlib import Path
def test_imports():
"""Test all module imports"""
try:
from app import SpaceGenerator
print("β
app.py imports successfully")
from utils import ConfigurationManager, AVAILABLE_THEMES, fetch_url_content
print("β
utils.py imports successfully")
from space_template import get_template, validate_template
print("β
space_template.py imports successfully")
from support_docs import create_support_docs
print("β
support_docs.py imports successfully")
return True
except Exception as e:
print(f"β Import error: {e}")
return False
def test_configuration():
"""Test configuration management"""
try:
from utils import ConfigurationManager
test_config = {
"assistant_name": "Test Assistant",
"system_prompt": "Test prompt",
"model_id": "gemini/gemini-1.5-flash-latest"
}
cm = ConfigurationManager(test_config)
print("β
ConfigurationManager initialized")
# Test save and load
cm.save_config(test_config)
loaded = cm.load_config()
print("β
Config save/load works")
return True
except Exception as e:
print(f"β Configuration error: {e}")
return False
def test_templates():
"""Test academic templates"""
try:
with open('academic_templates.json', 'r') as f:
templates = json.load(f)
print(f"β
Loaded {len(templates)} academic templates")
for name, template in templates.items():
required_fields = ['assistant_name', 'tagline', 'system_prompt', 'example_prompts']
for field in required_fields:
if field not in template:
print(f"β Template '{name}' missing field: {field}")
return False
print("β
All templates have required fields")
return True
except Exception as e:
print(f"β Template error: {e}")
return False
def test_space_template():
"""Test space template generation"""
try:
from space_template import get_template, validate_template
validate_template()
print("β
Template validation passed")
template = get_template()
print(f"β
Template size: {len(template)} characters")
# Check for critical placeholders
placeholders = [
'{assistant_name}',
'{system_prompt}',
'{model_id}',
'{temperature}',
'{max_tokens}'
]
for placeholder in placeholders:
if placeholder not in template:
print(f"β Missing placeholder: {placeholder}")
return False
print("β
All critical placeholders present")
return True
except Exception as e:
print(f"β Space template error: {e}")
return False
def test_themes():
"""Test theme availability"""
try:
from utils import AVAILABLE_THEMES
print(f"β
{len(AVAILABLE_THEMES)} themes available")
for name, theme_class in AVAILABLE_THEMES.items():
print(f" - {name}")
return True
except Exception as e:
print(f"β Theme error: {e}")
return False
def test_docs():
"""Test documentation files"""
try:
# Check docs.md exists and has content
docs_path = Path('docs.md')
if not docs_path.exists():
print("β docs.md not found")
return False
content = docs_path.read_text()
print(f"β
docs.md exists ({len(content)} characters)")
# Check for images
import re
img_pattern = r'<img[^>]+src="([^"]+)"'
images = re.findall(img_pattern, content)
print(f"β
Found {len(images)} image references in docs.md")
# Check image files exist
img_dir = Path('img')
if img_dir.exists():
img_files = list(img_dir.glob('*.png'))
print(f"β
Found {len(img_files)} image files")
return True
except Exception as e:
print(f"β Documentation error: {e}")
return False
def main():
"""Run all tests"""
print("=" * 50)
print("ChatUI Helper Test Suite")
print("=" * 50)
tests = [
("Imports", test_imports),
("Configuration", test_configuration),
("Templates", test_templates),
("Space Template", test_space_template),
("Themes", test_themes),
("Documentation", test_docs)
]
results = []
for name, test_func in tests:
print(f"\n Testing {name}...")
success = test_func()
results.append((name, success))
print()
print("=" * 50)
print("Test Results Summary")
print("=" * 50)
for name, success in results:
status = "β
PASS" if success else "β FAIL"
print(f"{name:20} {status}")
total = len(results)
passed = sum(1 for _, s in results if s)
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\nπ All tests passed!")
return 0
else:
print(f"\nβ οΈ {total - passed} test(s) failed")
return 1
if __name__ == "__main__":
sys.exit(main()) |