mcp-office-tools/test_mcp_tools.py
Ryan Malloy c935cec7b6 Add MS Office-themed test dashboard with interactive reporting
- Self-contained HTML dashboard with MS Office 365 design
- pytest plugin captures inputs, outputs, and errors per test
- Unified orchestrator runs pytest + torture tests together
- Test files persisted in reports/test_files/ with relative links
- GitHub Actions workflow with PR comments and job summaries
- Makefile with convenient commands (test, view-dashboard, etc.)
- Works offline with embedded JSON data (no CORS issues)
2026-01-11 00:28:12 -07:00

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 mcp_office_tools.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())