aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-01-29 14:23:02 +0100
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-01-29 14:25:55 +0100
commit276180caa8d97f7da9229e5b999365316940b959 (patch)
tree7f85b7c65153e9c2cf45c1f893911255695aa351
parent6a9d5e8fccbc4c576a4f1bf4f7ff75f6c0393ab3 (diff)
barcodetest.py: Fix an error condition when called with python3
On python3, thie error may occur: /usr/bin/python3 /devel/v4l/zbar/test/barcodetest.py F ====================================================================== FAIL: runTest (__main__.BuiltinTestCase) /devel/v4l/zbar/examples/ean-13.png ---------------------------------------------------------------------- Traceback (most recent call last): File "/devel/v4l/zbar/test/barcodetest.py", line 168, in runTest compare_sources(expect, actual[0]) File "/devel/v4l/zbar/test/barcodetest.py", line 248, in compare_sources compare_maps(map_source(expect), map_source(actual), compare_indices) File "/devel/v4l/zbar/test/barcodetest.py", line 217, in compare_maps assert not errors, '\n'.join(errors) AssertionError: Traceback (most recent call last): File "/devel/v4l/zbar/test/barcodetest.py", line 200, in compare_maps compare_func(iexp, iact) File "/devel/v4l/zbar/test/barcodetest.py", line 269, in compare_indices compare_maps(map_index(expect), map_index(actual), compare_symbols) File "/devel/v4l/zbar/test/barcodetest.py", line 211, in compare_maps errors.append('missing expected result:\n' + toxml(iexp)) File "/devel/v4l/zbar/test/barcodetest.py", line 54, in toxml ET.ElementTree(node).write(s) File "/usr/lib64/python3.7/xml/etree/ElementTree.py", line 777, in write short_empty_elements=short_empty_elements) File "/usr/lib64/python3.7/contextlib.py", line 119, in __exit__ next(self.gen) File "/usr/lib64/python3.7/xml/etree/ElementTree.py", line 836, in _get_writer yield file.write File "/usr/lib64/python3.7/contextlib.py", line 524, in __exit__ raise exc_details[1] File "/usr/lib64/python3.7/contextlib.py", line 509, in __exit__ if cb(*exc_details): File "/usr/lib64/python3.7/contextlib.py", line 384, in _exit_wrapper callback(*args, **kwds) TypeError: string argument expected, got 'bytes' The reason is that iexp.get(str(ET.QName(TS, 'exception')) may return None. Add a clause to explicitly test for it. After the change, both python3 and python2 should work: $ /usr/bin/python3 /devel/v4l/zbar/test/barcodetest.py . ---------------------------------------------------------------------- Ran 1 test in 0.037s OK $ /usr/bin/python2 /devel/v4l/zbar/test/barcodetest.py . ---------------------------------------------------------------------- Ran 1 test in 0.042s OK Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rwxr-xr-xtest/barcodetest.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/test/barcodetest.py b/test/barcodetest.py
index 930f381..df3951d 100755
--- a/test/barcodetest.py
+++ b/test/barcodetest.py
@@ -205,10 +205,13 @@ def compare_maps(expect, actual, compare_func):
notes.append('TODO unexpected result:\n' + toxml(iact))
for key, iexp in expect.items():
- if iexp.get(str(ET.QName(TS, 'exception'))) == 'TODO':
- notes.append('TODO missing expected result:\n' + toxml(iexp))
- else:
- errors.append('missing expected result:\n' + toxml(iexp))
+
+ exc = iexp.get(str(ET.QName(TS, 'exception')))
+
+ if exc == 'TODO':
+ notes.append('TODO missing expected result:\n' + toxml(iexp))
+ elif exc is not None:
+ errors.append('missing expected result:\n' + toxml(iexp))
if len(notes) == 1:
print('(TODO)', end=' ', file=sys.stderr)

Privacy Policy