-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
126 lines (98 loc) · 3.65 KB
/
Copy pathtest_setup.py
File metadata and controls
126 lines (98 loc) · 3.65 KB
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
"""Test MCP and PyMuPDF imports and basic functionality."""
import sys
def test_imports():
"""Test that all required modules can be imported."""
print("Testing imports...")
try:
import fitz # PyMuPDF
print("✓ PyMuPDF (fitz) imported successfully")
except ImportError as e:
print(f"✗ PyMuPDF import failed: {e}")
return False
try:
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, TextContent
print("✓ MCP modules imported successfully")
except ImportError as e:
print(f"✗ MCP import failed: {e}")
return False
return True
def test_pdf_tools():
"""Test the PDF tools library."""
print("\nTesting PDF tools...")
try:
from pdf_tools import PDFLibrary
print("✓ pdf_tools module imported successfully")
# Initialize library
lib = PDFLibrary("books")
print("✓ PDFLibrary initialized")
# Test listing books (should work even with empty directory)
books = lib.list_books()
print(f"✓ list_books() works - found {len(books)} book(s)")
if books:
print(f" Books: {', '.join(books)}")
else:
print(" Note: No PDFs in books/ directory yet")
return True
except Exception as e:
print(f"✗ PDF tools test failed: {e}")
return False
def test_server_structure():
"""Test that the server can be loaded."""
print("\nTesting server structure...")
try:
import server
print("✓ server.py imported successfully")
# Check that key components exist
if hasattr(server, 'app'):
print("✓ MCP server instance (app) exists")
else:
print("✗ Server instance not found")
return False
if hasattr(server, 'pdf_lib'):
print("✓ PDF library instance exists")
else:
print("✗ PDF library instance not found")
return False
return True
except Exception as e:
print(f"✗ Server structure test failed: {e}")
return False
def main():
"""Run all tests."""
print("=" * 50)
print("PDF-RAG Setup Verification")
print("=" * 50)
results = []
# Run tests
results.append(("Import Test", test_imports()))
results.append(("PDF Tools Test", test_pdf_tools()))
results.append(("Server Structure Test", test_server_structure()))
# Print summary
print("\n" + "=" * 50)
print("Test Summary")
print("=" * 50)
all_passed = True
for name, passed in results:
status = "PASS" if passed else "FAIL"
symbol = "✓" if passed else "✗"
print(f"{symbol} {name}: {status}")
if not passed:
all_passed = False
print("=" * 50)
if all_passed:
print("\n✓ All tests passed! Setup is complete.")
print("\nNext steps:")
print("1. Add PDF files to the books/ directory")
print("2. Configure your MCP client (see SETUP.md)")
print("3. Run: python server.py")
return 0
else:
print("\n✗ Some tests failed. Please check the errors above.")
print("\nTo fix:")
print("1. Install dependencies: python -m pip install -r requirements.txt")
print("2. Ensure all files are present (server.py, pdf_tools.py)")
return 1
if __name__ == "__main__":
sys.exit(main())