File size: 3,352 Bytes
7b6b271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script for the Gradio UI functionality
"""

import sys
import os

# Add paths for imports
sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'hf_space'))
sys.path.append(os.path.dirname(os.path.dirname(__file__)))

def test_mcp_client():
    """Test the MCP client integration"""
    print("πŸ§ͺ Testing MCP Client Integration...")
    
    try:
        from mcp_client import find_best_spots
        
        # Test with a simple location
        print("   Testing: MΓ‘laga, Spain")
        result = find_best_spots("MΓ‘laga, Spain", max_distance_km=50, top_n=3)
        
        if result.get("ok"):
            spots = result.get("results", [])
            ai_summary = result.get("ai_summary", "")
            
            print(f"   βœ… Found {len(spots)} surf spots")
            if ai_summary:
                print(f"   πŸ€– AI Summary: {ai_summary[:100]}...")
            
            for i, spot in enumerate(spots[:2], 1):
                print(f"   {i}. {spot['name']} - Score: {spot['score']}/100")
                
            return True
        else:
            print(f"   ❌ Error: {result.get('error')}")
            return False
            
    except Exception as e:
        print(f"   πŸ’₯ Exception: {e}")
        return False

def test_ui_functions():
    """Test UI formatting functions"""
    print("\n🎨 Testing UI Functions...")
    
    try:
        from app import format_spot_results, run_surf_finder
        
        # Test with sample data
        sample_spots = [
            {
                "name": "Test Spot",
                "score": 85.5,
                "distance_km": 25.3,
                "conditions": {"wave_height": 1.5, "wind_speed": 10},
                "explain": "Good conditions for surfing with moderate waves and favorable wind direction"
            }
        ]
        
        spots_html, ai_html, reasoning = format_spot_results(sample_spots, "Test AI summary")
        
        if "Test Spot" in spots_html and "85.5" in spots_html:
            print("   βœ… Spot formatting works correctly")
        else:
            print("   ❌ Spot formatting failed")
            return False
            
        if "Test AI summary" in ai_html:
            print("   βœ… AI summary formatting works")
        else:
            print("   ❌ AI summary formatting failed")
            return False
            
        return True
        
    except Exception as e:
        print(f"   πŸ’₯ Exception: {e}")
        return False

def main():
    """Run all tests"""
    print("πŸš€ Testing Surf Spot Finder UI Components")
    print("=" * 50)
    
    # Test MCP integration
    client_ok = test_mcp_client()
    
    # Test UI functions
    ui_ok = test_ui_functions()
    
    print("\n" + "=" * 50)
    print("πŸ“Š Test Results:")
    print(f"   MCP Client: {'βœ…' if client_ok else '❌'}")
    print(f"   UI Functions: {'βœ…' if ui_ok else '❌'}")
    
    if client_ok and ui_ok:
        print("\nπŸŽ‰ All tests passed! UI is ready for deployment.")
        print("πŸ’‘ The Gradio app should work correctly on HF Space.")
    else:
        print("\n⚠️  Some tests failed. Check the issues above.")
    
    return client_ok and ui_ok

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)