#!/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")