test/test_python.py: make it a little more generic

Change the script to be used either by printing the decoded
var or check. The behavior depends on having just one argument
(the image) or two: image and expected answer.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
Mauro Carvalho Chehab 2019-05-12 09:13:23 -03:00
parent fab5eaa49d
commit d67faf8ea6

View File

@ -28,12 +28,11 @@ except:
print("No image library on python. Aborting test")
sys.exit()
if len(sys.argv) < 2:
print("Usage: %s <file name> <expected text>")
if len(sys.argv) < 1 or len(sys.argv) > 3:
print("Usage: %s <file name> [<expected text to check>]")
sys.exit(-1)
filename = sys.argv[1]
text = sys.argv[2]
org_image = Image.open(filename)
@ -47,13 +46,19 @@ scanner = zbar.ImageScanner()
image = zbar.Image(width=width, height=height, format='Y800', data=raw_data)
scanner.scan(image)
found = False
for symbol in image:
if symbol.data == text:
print("OK")
found = True
else:
print("Expecting %s, received %s" % (text, symbol.data))
if len(sys.argv) == 3:
text = sys.argv[2]
if not found:
print("Can't process file")
found = False
for symbol in image:
found = True
if symbol.data == text:
print("OK")
else:
print("Expecting %s, received %s" % (text, symbol.data))
if not found:
print("Can't process file")
else:
for symbol in image:
print("Decoded as %s" % symbol.data)