Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script for the SitegeistAI package structure. | |
| This tests the package imports and individual components. | |
| """ | |
| import sys | |
| import os | |
| # Add the current directory to the Python path to import the package | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| try: | |
| from sitegeist_core import ( | |
| WebScraper, | |
| SEOAnalyzer, | |
| ReadabilityAnalyzer, | |
| ContentAnalyzer, | |
| KeywordAnalyzer, | |
| AnalysisOrchestrator, | |
| app # Modal app | |
| ) | |
| print("✅ Successfully imported SitegeistAI core package") | |
| except ImportError as e: | |
| print(f"❌ Failed to import package: {e}") | |
| sys.exit(1) | |
| import json | |
| def test_package_imports(): | |
| """Test that all package imports work correctly.""" | |
| print("🧪 Testing Package Imports\n") | |
| # Test that classes are available | |
| assert WebScraper is not None, "WebScraper not imported" | |
| assert SEOAnalyzer is not None, "SEOAnalyzer not imported" | |
| assert ReadabilityAnalyzer is not None, "ReadabilityAnalyzer not imported" | |
| assert ContentAnalyzer is not None, "ContentAnalyzer not imported" | |
| assert KeywordAnalyzer is not None, "KeywordAnalyzer not imported" | |
| assert AnalysisOrchestrator is not None, "AnalysisOrchestrator not imported" | |
| assert app is not None, "Modal app not imported" | |
| print("✅ All package components imported successfully") | |
| print(f" Modal App: {app.name}") | |
| print(f" Available Classes: {len([WebScraper, SEOAnalyzer, ReadabilityAnalyzer, ContentAnalyzer, KeywordAnalyzer, AnalysisOrchestrator])}") | |
| def test_individual_components(): | |
| """Test each component individually.""" | |
| print("\n🧪 Testing Individual Analysis Components\n") | |
| # Test URL | |
| test_url = "https://example.com" | |
| # 1. Test Web Scraper | |
| print("1. Testing WebScraper...") | |
| scraper = WebScraper() | |
| scraped_result = scraper.scrape_url(test_url) | |
| print(f" Status: {scraped_result['status']}") | |
| if scraped_result['status'] == 'success': | |
| print(f" Content Length: {scraped_result['content_length']} chars") | |
| print(f" Meta Title: {scraped_result['meta_title'][:50]}...") | |
| # 2. Test SEO Analyzer (only if scraping succeeded) | |
| if scraped_result['status'] == 'success': | |
| print("\n2. Testing SEOAnalyzer...") | |
| seo_analyzer = SEOAnalyzer() | |
| seo_result = seo_analyzer.analyze_seo_metrics(scraped_result, test_url) | |
| if 'error' not in seo_result: | |
| print(f" Internal Links: {seo_result['internal_links']}") | |
| print(f" External Links: {seo_result['external_links']}") | |
| print(f" Title SEO Friendly: {seo_result['title_seo_friendly']}") | |
| # 3. Test Readability Analyzer | |
| print("\n3. Testing ReadabilityAnalyzer...") | |
| readability_analyzer = ReadabilityAnalyzer() | |
| text_content = scraped_result.get('text_content', '') | |
| readability_result = readability_analyzer.analyze_readability(text_content) | |
| if 'error' not in readability_result: | |
| print(f" Word Count: {readability_result['word_count']}") | |
| print(f" Reading Difficulty: {readability_result['reading_difficulty']}") | |
| print(f" Flesch Score: {readability_result['flesch_reading_ease']:.1f}") | |
| # 4. Test Content Analyzer | |
| print("\n4. Testing ContentAnalyzer...") | |
| content_analyzer = ContentAnalyzer() | |
| content_result = content_analyzer.analyze_content_structure(text_content, scraped_result) | |
| if 'error' not in content_result: | |
| print(f" Paragraph Count: {content_result['paragraph_count']}") | |
| print(f" Has Questions: {content_result['has_questions']}") | |
| print(f" CTA Count: {content_result['cta_count']}") | |
| # 5. Test Keyword Analyzer | |
| print("\n5. Testing KeywordAnalyzer...") | |
| keyword_analyzer = KeywordAnalyzer() | |
| keyword_result = keyword_analyzer.extract_basic_keywords(text_content) | |
| if 'error' not in keyword_result: | |
| print(f" Total Words: {keyword_result['total_words']}") | |
| print(f" Unique Words: {keyword_result['unique_words']}") | |
| print(f" Top Keywords: {[kw['word'] for kw in keyword_result['top_keywords'][:3]]}") | |
| def test_orchestrator(): | |
| """Test the analysis orchestrator.""" | |
| print("\n\n🎯 Testing Analysis Orchestrator\n") | |
| orchestrator = AnalysisOrchestrator() | |
| test_url = "https://example.com" | |
| result = orchestrator.analyze_url_comprehensive(test_url) | |
| print(f"Status: {result['status']}") | |
| if result['status'] == 'success': | |
| analysis = result['analysis'] | |
| print(f"Analysis Components Found: {list(analysis.keys())}") | |
| # Print key metrics from each component | |
| if 'seo_metrics' in analysis and 'error' not in analysis['seo_metrics']: | |
| seo = analysis['seo_metrics'] | |
| print(f"SEO: {seo['internal_links']} internal, {seo['external_links']} external links") | |
| if 'readability_metrics' in analysis and 'error' not in analysis['readability_metrics']: | |
| readability = analysis['readability_metrics'] | |
| print(f"Readability: {readability['word_count']} words, {readability['reading_difficulty']}") | |
| if 'keyword_analysis' in analysis and 'error' not in analysis['keyword_analysis']: | |
| keywords = analysis['keyword_analysis'] | |
| print(f"Keywords: {keywords['unique_words']} unique words") | |
| if 'content_structure' in analysis and 'error' not in analysis['content_structure']: | |
| structure = analysis['content_structure'] | |
| print(f"Structure: {structure['paragraph_count']} paragraphs, {structure['cta_count']} CTAs") | |
| def test_modal_app_info(): | |
| """Test Modal app information.""" | |
| print("\n\n🚀 Testing Modal App Configuration\n") | |
| print(f"App Name: {app.name}") | |
| print(f"App Type: {type(app)}") | |
| # Note: Functions are only available when running in Modal context | |
| print("Note: Modal functions are registered but only callable when deployed to Modal") | |
| if __name__ == "__main__": | |
| print("🚀 SitegeistAI Package Test Suite") | |
| print("=" * 50) | |
| # Run tests | |
| test_package_imports() | |
| test_individual_components() | |
| test_orchestrator() | |
| test_modal_app_info() | |
| print("\n✅ Package test suite completed!") | |
| print("\nDeployment Commands:") | |
| print(" Local test: python test_package_components.py") | |
| print(" Deploy Modal: modal deploy -m sitegeist_core.modal_functions") | |
| print(" Run Modal test: modal run -m sitegeist_core.modal_functions") | |
| print("\nNote: This test uses real web requests.") | |
| print("Some tests may fail due to network issues or website availability.") |