Some checks are pending
Test Dashboard / test-and-dashboard (push) Waiting to run
Named for Milton Waddams, who was relocated to the basement with boxes of legacy documents. He handles the .doc and .xls files from 1997 that nobody else wants to touch. - Rename package from mcp-office-tools to mcwaddams - Update author to Ryan Malloy - Update all imports and references - Add Office Space themed README narrative - All 53 tests passing
97 lines
3.3 KiB
Python
97 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Simple test script to verify MCP Office Tools functionality."""
|
|
|
|
import asyncio
|
|
import tempfile
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Create simple test documents
|
|
def create_test_documents():
|
|
"""Create test documents for verification."""
|
|
temp_dir = Path(tempfile.mkdtemp())
|
|
|
|
# Create a simple CSV file
|
|
csv_path = temp_dir / "test.csv"
|
|
csv_content = """Name,Age,City
|
|
John Doe,30,New York
|
|
Jane Smith,25,Los Angeles
|
|
Bob Johnson,35,Chicago"""
|
|
|
|
with open(csv_path, 'w') as f:
|
|
f.write(csv_content)
|
|
|
|
# Create a simple text file to test validation
|
|
txt_path = temp_dir / "test.txt"
|
|
with open(txt_path, 'w') as f:
|
|
f.write("This is a simple text file, not an Office document.")
|
|
|
|
return temp_dir, csv_path, txt_path
|
|
|
|
async def test_mcp_server():
|
|
"""Test MCP server functionality."""
|
|
print("🧪 Testing MCP Office Tools Server")
|
|
print("=" * 50)
|
|
|
|
# Create test documents
|
|
temp_dir, csv_path, txt_path = create_test_documents()
|
|
print(f"📁 Created test files in: {temp_dir}")
|
|
|
|
try:
|
|
# Import the server components
|
|
from mcwaddams.mixins import UniversalMixin
|
|
|
|
# Test the Universal Mixin directly
|
|
universal = UniversalMixin()
|
|
|
|
print("\n🔍 Testing extract_text with CSV file...")
|
|
try:
|
|
result = await universal.extract_text(str(csv_path))
|
|
print("✅ CSV text extraction successful!")
|
|
print(f" Text length: {len(result.get('text', ''))}")
|
|
print(f" Method used: {result.get('method_used', 'unknown')}")
|
|
except Exception as e:
|
|
print(f"❌ CSV text extraction failed: {e}")
|
|
|
|
print("\n🔍 Testing get_supported_formats...")
|
|
try:
|
|
result = await universal.get_supported_formats()
|
|
print("✅ Supported formats query successful!")
|
|
print(f" Total formats: {len(result.get('formats', []))}")
|
|
print(f" Excel formats: {len([f for f in result.get('formats', []) if 'Excel' in f.get('description', '')])}")
|
|
except Exception as e:
|
|
print(f"❌ Supported formats query failed: {e}")
|
|
|
|
print("\n🔍 Testing validation with unsupported file...")
|
|
try:
|
|
result = await universal.extract_text(str(txt_path))
|
|
print("❌ Should have failed with unsupported file!")
|
|
except Exception as e:
|
|
print(f"✅ Correctly rejected unsupported file: {type(e).__name__}")
|
|
|
|
print("\n🔍 Testing detect_office_format...")
|
|
try:
|
|
result = await universal.detect_office_format(str(csv_path))
|
|
print("✅ Format detection successful!")
|
|
print(f" Detected format: {result.get('format', 'unknown')}")
|
|
print(f" Is supported: {result.get('is_supported', False)}")
|
|
except Exception as e:
|
|
print(f"❌ Format detection failed: {e}")
|
|
|
|
except ImportError as e:
|
|
print(f"❌ Failed to import server components: {e}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Unexpected error: {e}")
|
|
return False
|
|
finally:
|
|
# Cleanup
|
|
import shutil
|
|
shutil.rmtree(temp_dir)
|
|
print(f"\n🧹 Cleaned up test files from: {temp_dir}")
|
|
|
|
print("\n✅ Basic MCP Office Tools testing completed!")
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_mcp_server()) |