File size: 6,832 Bytes
1744e85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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.")