-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathtest_basic.py
More file actions
224 lines (168 loc) · 6.02 KB
/
test_basic.py
File metadata and controls
224 lines (168 loc) · 6.02 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# -*- coding: UTF-8 -*-
"""Test script for PDF to Word converter.
PDF转Word转换器的测试脚本。
This script tests the basic functionality of the converter without GUI.
该脚本在不使用GUI的情况下测试转换器的基本功能。
"""
import sys
import os
from pathlib import Path
# Add parent directory to path
# 添加父目录到路径
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from gui.pdf2word.models.converter import PDFConverter
from gui.pdf2word.utils.file_manager import FileManager
def test_converter():
"""Test PDF converter functionality.
测试PDF转换器功能。
"""
print("=== Testing PDF Converter ===")
converter = PDFConverter()
print("✓ Converter initialized successfully")
# Test validation
# 测试验证
result = converter.convert("nonexistent.pdf")
assert not result['success'], "Should fail for non-existent file"
print("✓ File validation works")
result = converter.convert("test.txt")
assert not result['success'], "Should fail for non-PDF file"
print("✓ File extension validation works")
print("\n=== PDF Converter Tests Passed ===\n")
def test_file_manager():
"""Test file manager functionality.
测试文件管理器功能。
"""
print("=== Testing File Manager ===")
manager = FileManager()
print("✓ File manager initialized successfully")
# Test file validation
# 测试文件验证
is_valid = manager.validate_file("nonexistent.pdf")
assert not is_valid, "Should fail for non-existent file"
print("✓ File validation works")
# Test adding files (without actual files)
# 测试添加文件(不使用实际文件)
count = manager.get_file_count()
assert count == 0, "Initial count should be 0"
print("✓ Initial file count is correct")
# Test status count
# 测试状态计数
counts = manager.get_status_count()
assert counts['waiting'] == 0, "Initial waiting count should be 0"
print("✓ Status count works")
# Test clear
# 测试清空
manager.clear_files()
assert manager.get_file_count() == 0, "Count should be 0 after clear"
print("✓ Clear files works")
print("\n=== File Manager Tests Passed ===\n")
def main():
"""Run all tests.
运行所有测试。
"""
try:
print("\n" + "="*50)
print("PDF to Word Converter - Unit Tests")
print("PDF转Word转换器 - 单元测试")
print("="*50 + "\n")
test_converter()
test_file_manager()
print("="*50)
print("All Tests Passed! ✓")
print("所有测试通过!✓")
print("="*50 + "\n")
return 0
except AssertionError as e:
print(f"\n✗ Test failed: {e}")
return 1
except Exception as e:
print(f"\n✗ Error during testing: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == '__main__':
sys.exit(main())
# -*- coding: UTF-8 -*-
"""Test script for PDF to Word converter.
PDF转Word转换器的测试脚本。
This script tests the basic functionality of the converter without GUI.
该脚本在不使用GUI的情况下测试转换器的基本功能。
"""
import sys
import os
from pathlib import Path
# Add parent directory to path
# 添加父目录到路径
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from gui.pdf2word.models.converter import PDFConverter
from gui.pdf2word.utils.file_manager import FileManager
def test_converter():
"""Test PDF converter functionality.
测试PDF转换器功能。
"""
print("=== Testing PDF Converter ===")
converter = PDFConverter()
print("✓ Converter initialized successfully")
# Test validation
# 测试验证
result = converter.convert("nonexistent.pdf")
assert not result['success'], "Should fail for non-existent file"
print("✓ File validation works")
result = converter.convert("test.txt")
assert not result['success'], "Should fail for non-PDF file"
print("✓ File extension validation works")
print("\n=== PDF Converter Tests Passed ===\n")
def test_file_manager():
"""Test file manager functionality.
测试文件管理器功能。
"""
print("=== Testing File Manager ===")
manager = FileManager()
print("✓ File manager initialized successfully")
# Test file validation
# 测试文件验证
is_valid = manager.validate_file("nonexistent.pdf")
assert not is_valid, "Should fail for non-existent file"
print("✓ File validation works")
# Test adding files (without actual files)
# 测试添加文件(不使用实际文件)
count = manager.get_file_count()
assert count == 0, "Initial count should be 0"
print("✓ Initial file count is correct")
# Test status count
# 测试状态计数
counts = manager.get_status_count()
assert counts['waiting'] == 0, "Initial waiting count should be 0"
print("✓ Status count works")
# Test clear
# 测试清空
manager.clear_files()
assert manager.get_file_count() == 0, "Count should be 0 after clear"
print("✓ Clear files works")
print("\n=== File Manager Tests Passed ===\n")
def main():
"""Run all tests.
运行所有测试。
"""
try:
print("\n" + "="*50)
print("PDF to Word Converter - Unit Tests")
print("PDF转Word转换器 - 单元测试")
print("="*50 + "\n")
test_converter()
test_file_manager()
print("="*50)
print("All Tests Passed! ✓")
print("所有测试通过!✓")
print("="*50 + "\n")
return 0
except AssertionError as e:
print(f"\n✗ Test failed: {e}")
return 1
except Exception as e:
print(f"\n✗ Error during testing: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == '__main__':
sys.exit(main())