ProofCheck / test_barcode.py
Yaz Hobooti
Add barcode detection debugging and test script
ad64d27
#!/usr/bin/env python3
"""
Simple test script to verify barcode reader functionality
"""
def test_barcode_imports():
"""Test if all required modules can be imported"""
print("Testing barcode reader imports...")
try:
import numpy as np
print("βœ“ numpy imported")
except Exception as e:
print(f"βœ— numpy failed: {e}")
return False
try:
from PIL import Image
print("βœ“ PIL imported")
except Exception as e:
print(f"βœ— PIL failed: {e}")
return False
try:
import cv2
print("βœ“ OpenCV imported")
has_barcode = hasattr(cv2, 'barcode') and hasattr(getattr(cv2, 'barcode'), 'BarcodeDetector')
print(f"βœ“ OpenCV barcode detector: {has_barcode}")
except Exception as e:
print(f"βœ— OpenCV failed: {e}")
return False
try:
import zxingcpp
print("βœ“ zxingcpp imported")
except Exception as e:
print(f"βœ— zxingcpp failed: {e}")
return False
try:
import fitz
print("βœ“ PyMuPDF imported")
except Exception as e:
print(f"βœ— PyMuPDF failed: {e}")
return False
try:
from barcode_reader import read_barcodes_from_path
print("βœ“ barcode_reader imported")
return True
except Exception as e:
print(f"βœ— barcode_reader failed: {e}")
return False
def test_barcode_function():
"""Test the barcode reader function with a simple case"""
print("\nTesting barcode reader function...")
try:
from barcode_reader import read_barcodes_from_path
print("βœ“ read_barcodes_from_path function available")
# Test with a non-existent file (should return empty list, not crash)
result = read_barcodes_from_path("nonexistent.pdf")
print(f"βœ“ Function handles non-existent file: {type(result)}")
return True
except Exception as e:
print(f"βœ— barcode function test failed: {e}")
return False
if __name__ == "__main__":
print("=== Barcode Reader Test ===")
imports_ok = test_barcode_imports()
if imports_ok:
function_ok = test_barcode_function()
if function_ok:
print("\nβœ“ All tests passed!")
else:
print("\nβœ— Function test failed")
else:
print("\nβœ— Import tests failed")