forked from PatrickLib/captcha_recognize
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_basic.py
More file actions
127 lines (95 loc) · 3.79 KB
/
test_basic.py
File metadata and controls
127 lines (95 loc) · 3.79 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
#!/usr/bin/env python3
"""
Basic test script to verify the refactored CAPTCHA recognizer works.
"""
import sys
from pathlib import Path
# Add the current directory to Python path
sys.path.insert(0, str(Path(__file__).parent))
def test_imports():
"""Test that all modules can be imported correctly."""
try:
from captcha_recognizer import Config, ModelConfig, TrainingConfig, DataConfig
print("✓ Configuration classes imported successfully")
from captcha_recognizer import CaptchaModel, create_model
print("✓ Model classes imported successfully")
from captcha_recognizer import CaptchaDataLoader
print("✓ Data loader imported successfully")
from captcha_recognizer import CaptchaTrainer
print("✓ Trainer imported successfully")
from captcha_recognizer import CaptchaPredictor
print("✓ Predictor imported successfully")
return True
except ImportError as e:
print(f"✗ Import failed: {e}")
return False
def test_configuration():
"""Test configuration system."""
try:
from captcha_recognizer import Config
# Test default configuration
config = Config()
print(f"✓ Default config created: image_size={config.model.input_shape}")
# Test custom configuration
custom_config = Config(
training=TrainingConfig(batch_size=64, epochs=50)
)
print(f"✓ Custom config created: batch_size={custom_config.training.batch_size}")
return True
except Exception as e:
print(f"✗ Configuration test failed: {e}")
return False
def test_model_creation():
"""Test model creation."""
try:
from captcha_recognizer import create_model, ModelConfig
config = ModelConfig()
model = create_model(config)
print(f"✓ Model created successfully with {model.count_params()} parameters")
print(f"✓ Model input shape: {model.input_shape}")
print(f"✓ Model output layers: {len(model.output_names)}")
return True
except Exception as e:
print(f"✗ Model creation test failed: {e}")
return False
def test_data_loader():
"""Test data loader functionality."""
try:
from captcha_recognizer import CaptchaDataLoader, Config
config = Config()
data_loader = CaptchaDataLoader(config.data, config.model)
print("✓ Data loader created successfully")
# Test synthetic dataset creation
synthetic_dataset = data_loader.create_synthetic_dataset(10)
print(f"✓ Synthetic dataset created with {len(list(synthetic_dataset))} batches")
return True
except Exception as e:
print(f"✗ Data loader test failed: {e}")
return False
def main():
"""Run all tests."""
print("🧪 Testing Refactored CAPTCHA Recognizer\n")
tests = [
("Import Test", test_imports),
("Configuration Test", test_configuration),
("Model Creation Test", test_model_creation),
("Data Loader Test", test_data_loader),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n--- {test_name} ---")
if test_func():
passed += 1
else:
print(f"✗ {test_name} failed")
print(f"\n{'='*50}")
print(f"Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! The refactored system is working correctly.")
return 0
else:
print("❌ Some tests failed. Please check the errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())