132 lines
No EOL
3.9 KiB
Python
132 lines
No EOL
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for hybrid detection implementation
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Add current directory to Python path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
def test_hybrid_import():
|
|
"""Test that hybrid detector can be imported"""
|
|
try:
|
|
from hybrid_detector import HybridImageDetector
|
|
print("✓ Successfully imported HybridImageDetector")
|
|
return True
|
|
except ImportError as e:
|
|
print(f"✗ Failed to import HybridImageDetector: {e}")
|
|
return False
|
|
|
|
def test_hybrid_initialization():
|
|
"""Test hybrid detector initialization"""
|
|
try:
|
|
from hybrid_detector import HybridImageDetector
|
|
|
|
# Test with default settings
|
|
detector = HybridImageDetector()
|
|
print("✓ Successfully initialized HybridImageDetector with defaults")
|
|
|
|
# Test with custom settings
|
|
detector2 = HybridImageDetector(
|
|
panel_threshold=3,
|
|
inlier_threshold=0.7,
|
|
enable_greyscale=True,
|
|
enable_contrast_enhancement=True
|
|
)
|
|
print("✓ Successfully initialized HybridImageDetector with custom settings")
|
|
|
|
# Check attributes
|
|
assert detector.panel_threshold == 2
|
|
assert detector.inlier_threshold == 0.65
|
|
assert detector.enable_greyscale == False
|
|
assert detector.enable_contrast_enhancement == False
|
|
|
|
assert detector2.panel_threshold == 3
|
|
assert detector2.inlier_threshold == 0.7
|
|
assert detector2.enable_greyscale == True
|
|
assert detector2.enable_contrast_enhancement == True
|
|
|
|
print("✓ All attributes set correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"✗ Failed to initialize HybridImageDetector: {e}")
|
|
return False
|
|
|
|
def test_required_files():
|
|
"""Test that required files exist"""
|
|
required_files = [
|
|
"layouts/",
|
|
"master_images/",
|
|
"openai_detector.py",
|
|
"hybrid_detector.py"
|
|
]
|
|
|
|
missing_files = []
|
|
for file_path in required_files:
|
|
if not os.path.exists(file_path):
|
|
missing_files.append(file_path)
|
|
|
|
if missing_files:
|
|
print(f"✗ Missing required files: {missing_files}")
|
|
return False
|
|
else:
|
|
print("✓ All required files exist")
|
|
return True
|
|
|
|
def test_cli_help():
|
|
"""Test CLI help includes hybrid mode"""
|
|
try:
|
|
import subprocess
|
|
result = subprocess.run([sys.executable, "cli.py", "--help"],
|
|
capture_output=True, text=True)
|
|
|
|
if "--hybrid" in result.stdout:
|
|
print("✓ CLI help includes --hybrid flag")
|
|
return True
|
|
else:
|
|
print("✗ CLI help does not include --hybrid flag")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Failed to test CLI help: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Run all tests"""
|
|
print("Testing Hybrid Detection Implementation")
|
|
print("=" * 50)
|
|
|
|
tests = [
|
|
("Import Test", test_hybrid_import),
|
|
("Initialization Test", test_hybrid_initialization),
|
|
("Required Files Test", test_required_files),
|
|
("CLI Help Test", test_cli_help)
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test_name, test_func in tests:
|
|
print(f"\n{test_name}:")
|
|
try:
|
|
if test_func():
|
|
passed += 1
|
|
except Exception as e:
|
|
print(f"✗ {test_name} failed with exception: {e}")
|
|
|
|
print(f"\n{'=' * 50}")
|
|
print(f"Test Results: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All tests passed! Hybrid implementation is ready.")
|
|
return 0
|
|
else:
|
|
print("❌ Some tests failed. Please check the implementation.")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |