#!/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']+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())