Skip to contentSkip to conversation

tests/functional: Fix bad usage of has_cmd

PATCH In review Thomas Huth 4 participants 4 messages Sep 10, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/functional: Fix bad usage of has_cmd

has_cmd returns a tuple, not a boolean value. This fixes a crash when e.g. "tesseract" is not available in the test_m68k_nextcube test.

---
 tests/functional/qemu_test/cmd.py       | 6 +++---
 tests/functional/qemu_test/tesseract.py | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)
tests/functional/qemu_test/cmd.py +3 -3
index 3acd617324..cbabb1ceed 100644
@@ -187,7 +187,7 @@ def get_qemu_img(test):
     qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
     if os.path.exists(qemu_img):
         return qemu_img
-    if has_cmd('qemu-img'):
+    (has_system_qemu_img, errmsg) = has_cmd('qemu-img')
+    if has_system_qemu_img:
         return 'qemu-img'
-    test.skipTest('Could not find "qemu-img", which is required to '
-                  'create temporary images')
+    test.skipTest(errmsg)
tests/functional/qemu_test/tesseract.py +2 -1
index c4087b7c11..db441027b9 100644
@@ -11,7 +11,8 @@
 from . import has_cmd, run_cmd
 
 def tesseract_available(expected_version):
-    if not has_cmd('tesseract'):
+    (has_tesseract, _) = has_cmd('tesseract')
+    if not has_tesseract:
         return False
     (stdout, stderr, ret) = run_cmd([ 'tesseract', '--version'])
     if ret:
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Thomas Huth

has_cmd returns a tuple, not a boolean value. This fixes a crash when e.g. "tesseract" is not available in the test_m68k_nextcube test.

---
 tests/functional/qemu_test/cmd.py       | 6 +++---
 tests/functional/qemu_test/tesseract.py | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/1
#2 lore raw
In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

has_cmd returns a tuple, not a boolean value. This fixes a crash when e.g. "tesseract" is not available in the test_m68k_nextcube test.

---
  tests/functional/qemu_test/cmd.py       | 6 +++---
  tests/functional/qemu_test/tesseract.py | 3 ++-
  2 files changed, 5 insertions(+), 4 deletions(-)
Reviewed-by on v1 1/1
#3 lore raw
In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

has_cmd returns a tuple, not a boolean value. This fixes a crash when e.g. "tesseract" is not available in the test_m68k_nextcube test.

---
  tests/functional/qemu_test/cmd.py       | 6 +++---
  tests/functional/qemu_test/tesseract.py | 3 ++-
  2 files changed, 5 insertions(+), 4 deletions(-)

r~