-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
158 lines (139 loc) · 4.5 KB
/
test_basic.py
File metadata and controls
158 lines (139 loc) · 4.5 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
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
#!/usr/bin/env python3
"""
Minimal Test - Verify PDF Organizer Works
Tests the basic functionality step by step
"""
import sys
from pathlib import Path
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
if hasattr(sys.stderr, "reconfigure"):
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
print("="*70)
print(" PDF Organizer - Basic Test")
print("="*70)
print()
# Test 1: Imports
print("Test 1: Checking imports...")
try:
from google import genai as google_genai
import anthropic
import openai
from pypdf import PdfReader
import pdfplumber
print("✓ All imports successful")
except ImportError as e:
print(f"❌ Import failed: {e}")
print("\nRun: pip install -r requirements.txt")
input("\nPress Enter to exit...")
sys.exit(1)
# Test 2: API Key
print("\nTest 2: Checking API key...")
print("Select provider for API test:")
print("1) Gemini")
print("2) Anthropic")
print("3) DeepSeek")
provider_choice = input("Select provider [1]: ").strip().lower()
if provider_choice in ['2', 'anthropic', 'a']:
provider = "anthropic"
elif provider_choice in ['3', 'deepseek', 'd']:
provider = "deepseek"
else:
provider = "gemini"
if provider == "anthropic":
api_key = input("Enter your Anthropic API key (or press Enter to skip): ").strip()
elif provider == "deepseek":
api_key = input("Enter your DeepSeek API key (or press Enter to skip): ").strip()
else:
api_key = input("Enter your Gemini API key (or press Enter to skip): ").strip()
if not api_key:
print("⚠ Skipping API test")
else:
print(f"✓ Using provided key: {api_key[:10]}...")
# Test 3: Create test folders
print("\nTest 3: Creating test folders...")
test_dir = Path.home() / "pdf_organizer_test"
test_downloads = test_dir / "downloads"
test_ebooks = test_dir / "ebooks"
try:
test_downloads.mkdir(parents=True, exist_ok=True)
test_ebooks.mkdir(parents=True, exist_ok=True)
print(f"✓ Created: {test_dir}")
print(f" Downloads: {test_downloads}")
print(f" Ebooks: {test_ebooks}")
except Exception as e:
print(f"❌ Failed to create folders: {e}")
input("\nPress Enter to exit...")
sys.exit(1)
# Test 4: Test PDFOrganizer initialization
print("\nTest 4: Testing PDFOrganizer class...")
try:
from organize_batch import BatchPDFOrganizer
print("✓ BatchPDFOrganizer imported")
# Test with valid paths but no API key
if not api_key:
print("⚠ Skipping initialization test (no API key)")
else:
try:
organizer = BatchPDFOrganizer(
downloads_folder=str(test_downloads),
ebooks_folder=str(test_ebooks),
api_key=api_key,
provider=provider,
dry_run=True
)
print("✓ PDFOrganizer initialized successfully")
except Exception as e:
print(f"❌ Initialization failed: {e}")
import traceback
print("\nTraceback:")
print(traceback.format_exc())
except ImportError as e:
print(f"❌ Cannot import BatchPDFOrganizer: {e}")
print("\nMake sure organize_batch.py is in the same folder")
except Exception as e:
print(f"❌ Unexpected error: {e}")
import traceback
print("\nTraceback:")
print(traceback.format_exc())
# Test 5: Test with None values (should fail gracefully)
print("\nTest 5: Testing validation...")
try:
from organize_batch import BatchPDFOrganizer
try:
bad_organizer = BatchPDFOrganizer(
downloads_folder=None,
ebooks_folder=None,
api_key="test",
dry_run=True
)
print("⚠ WARNING: None values were accepted (validation not working)")
except ValueError as ve:
print(f"✓ Validation working correctly: {str(ve)[:60]}...")
except Exception as e:
print(f"⚠ Unexpected error type: {e}")
except Exception as e:
print(f"⚠ Could not test validation: {e}")
# Cleanup
print("\nTest 6: Cleanup...")
try:
import shutil
if test_dir.exists():
shutil.rmtree(test_dir)
print("✓ Cleaned up test folders")
except Exception as e:
print(f"⚠ Cleanup warning: {e}")
# Summary
print()
print("="*70)
print(" Test Summary")
print("="*70)
print()
print("If all tests passed, the organizer should work!")
print()
print("To use it:")
print("1. Make sure you have PDFs in your Downloads folder")
print("2. Run: python organize_batch.py")
print()
print("="*70)
input("\nPress Enter to exit...")