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