Spaces:
Running
Running
milwright
update project files: add config.json, test_app.py, update app.py, readme, and gitignore
9ad9eac
#!/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()) |