Yaz Hobooti commited on
Commit
ad64d27
Β·
1 Parent(s): 5fa0489

Add barcode detection debugging and test script

Browse files
Files changed (2) hide show
  1. app.py +9 -1
  2. test_barcode.py +83 -0
app.py CHANGED
@@ -54,9 +54,11 @@ except Exception:
54
  try:
55
  from barcode_reader import read_barcodes_from_path
56
  HAS_BARCODE = True
57
- except Exception:
 
58
  read_barcodes_from_path = None
59
  HAS_BARCODE = False
 
60
 
61
  # -------------------- Core Data --------------------
62
  @dataclass
@@ -1172,6 +1174,12 @@ def compare_pdfs(file_a, file_b):
1172
 
1173
  # Debug: Print barcode detection results
1174
  print(f"Barcode detection results - A: {len(bar_a)} codes, B: {len(bar_b)} codes")
 
 
 
 
 
 
1175
  except Exception as e:
1176
  print(f"Barcode detection error: {e}")
1177
  bar_a, info_a = [], []
 
54
  try:
55
  from barcode_reader import read_barcodes_from_path
56
  HAS_BARCODE = True
57
+ print("βœ“ Barcode reader imported successfully")
58
+ except Exception as e:
59
  read_barcodes_from_path = None
60
  HAS_BARCODE = False
61
+ print(f"βœ— Barcode reader import failed: {e}")
62
 
63
  # -------------------- Core Data --------------------
64
  @dataclass
 
1174
 
1175
  # Debug: Print barcode detection results
1176
  print(f"Barcode detection results - A: {len(bar_a)} codes, B: {len(bar_b)} codes")
1177
+ print(f"Raw codes_a: {len(codes_a)} items")
1178
+ print(f"Raw codes_b: {len(codes_b)} items")
1179
+ if codes_a:
1180
+ print(f"Sample code_a: {codes_a[0] if codes_a else 'None'}")
1181
+ if codes_b:
1182
+ print(f"Sample code_b: {codes_b[0] if codes_b else 'None'}")
1183
  except Exception as e:
1184
  print(f"Barcode detection error: {e}")
1185
  bar_a, info_a = [], []
test_barcode.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple test script to verify barcode reader functionality
4
+ """
5
+
6
+ def test_barcode_imports():
7
+ """Test if all required modules can be imported"""
8
+ print("Testing barcode reader imports...")
9
+
10
+ try:
11
+ import numpy as np
12
+ print("βœ“ numpy imported")
13
+ except Exception as e:
14
+ print(f"βœ— numpy failed: {e}")
15
+ return False
16
+
17
+ try:
18
+ from PIL import Image
19
+ print("βœ“ PIL imported")
20
+ except Exception as e:
21
+ print(f"βœ— PIL failed: {e}")
22
+ return False
23
+
24
+ try:
25
+ import cv2
26
+ print("βœ“ OpenCV imported")
27
+ has_barcode = hasattr(cv2, 'barcode') and hasattr(getattr(cv2, 'barcode'), 'BarcodeDetector')
28
+ print(f"βœ“ OpenCV barcode detector: {has_barcode}")
29
+ except Exception as e:
30
+ print(f"βœ— OpenCV failed: {e}")
31
+ return False
32
+
33
+ try:
34
+ import zxingcpp
35
+ print("βœ“ zxingcpp imported")
36
+ except Exception as e:
37
+ print(f"βœ— zxingcpp failed: {e}")
38
+ return False
39
+
40
+ try:
41
+ import fitz
42
+ print("βœ“ PyMuPDF imported")
43
+ except Exception as e:
44
+ print(f"βœ— PyMuPDF failed: {e}")
45
+ return False
46
+
47
+ try:
48
+ from barcode_reader import read_barcodes_from_path
49
+ print("βœ“ barcode_reader imported")
50
+ return True
51
+ except Exception as e:
52
+ print(f"βœ— barcode_reader failed: {e}")
53
+ return False
54
+
55
+ def test_barcode_function():
56
+ """Test the barcode reader function with a simple case"""
57
+ print("\nTesting barcode reader function...")
58
+
59
+ try:
60
+ from barcode_reader import read_barcodes_from_path
61
+ print("βœ“ read_barcodes_from_path function available")
62
+
63
+ # Test with a non-existent file (should return empty list, not crash)
64
+ result = read_barcodes_from_path("nonexistent.pdf")
65
+ print(f"βœ“ Function handles non-existent file: {type(result)}")
66
+
67
+ return True
68
+ except Exception as e:
69
+ print(f"βœ— barcode function test failed: {e}")
70
+ return False
71
+
72
+ if __name__ == "__main__":
73
+ print("=== Barcode Reader Test ===")
74
+
75
+ imports_ok = test_barcode_imports()
76
+ if imports_ok:
77
+ function_ok = test_barcode_function()
78
+ if function_ok:
79
+ print("\nβœ“ All tests passed!")
80
+ else:
81
+ print("\nβœ— Function test failed")
82
+ else:
83
+ print("\nβœ— Import tests failed")