[PATCH 1/4] tests/functional/qemu_test: Silence warnings from pylint in tesseract.py

Thomas Huth posted 4 patches 1 week, 4 days ago
Maintainers: Thomas Huth <th.huth+qemu@posteo.eu>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
[PATCH 1/4] tests/functional/qemu_test: Silence warnings from pylint in tesseract.py
Posted by Thomas Huth 1 week, 4 days ago
From: Thomas Huth <thuth@redhat.com>

Pylint complains:

 tesseract.py:1:0: C0114: Missing module docstring (missing-module-docstring)
 tesseract.py:12:0: C0116: Missing function or method docstring (missing-function-docstring)
 tesseract.py:15:11: W1510: 'subprocess.run' used without explicitly defining the value for 'check'. (subprocess-run-check)
 tesseract.py:12:30: W0613: Unused argument 'tesseract_args' (unused-argument)

Thus add the missing bits and remove the unused tesseract_args argument.
While we're at it, also add a SPDX identifier instead of the weird three
dots at the beginning of the file.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/functional/qemu_test/tesseract.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tests/functional/qemu_test/tesseract.py b/tests/functional/qemu_test/tesseract.py
index ede6c6501e2..1f955d32b76 100644
--- a/tests/functional/qemu_test/tesseract.py
+++ b/tests/functional/qemu_test/tesseract.py
@@ -1,19 +1,24 @@
-# ...
+# SPDX-License-Identifier: GPL-2.0-or-later
 #
 # Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
 #
 # This work is licensed under the terms of the GNU GPL, version 2 or
 # later. See the COPYING file in the top-level directory.
+'''
+Tesseract is an program for doing Optical Character Recognition (OCR),
+which can be used in the tests to extract text from screenshots.
+'''
 
 import logging
 from subprocess import run
 
 
-def tesseract_ocr(image_path, tesseract_args=''):
+def tesseract_ocr(image_path):
+    ''' Run the tesseract OCR to extract text from a screenshot '''
     console_logger = logging.getLogger('console')
     console_logger.debug(image_path)
     proc = run(['tesseract', image_path, 'stdout'],
-               capture_output=True, encoding='utf8')
+               capture_output=True, encoding='utf8', check=False)
     if proc.returncode:
         return None
     lines = []
-- 
2.53.0


Re: [PATCH 1/4] tests/functional/qemu_test: Silence warnings from pylint in tesseract.py
Posted by Philippe Mathieu-Daudé 1 week, 4 days ago
On 24/3/26 17:35, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> Pylint complains:
> 
>   tesseract.py:1:0: C0114: Missing module docstring (missing-module-docstring)
>   tesseract.py:12:0: C0116: Missing function or method docstring (missing-function-docstring)
>   tesseract.py:15:11: W1510: 'subprocess.run' used without explicitly defining the value for 'check'. (subprocess-run-check)
>   tesseract.py:12:30: W0613: Unused argument 'tesseract_args' (unused-argument)
> 
> Thus add the missing bits and remove the unused tesseract_args argument.
> While we're at it, also add a SPDX identifier instead of the weird three
> dots at the beginning of the file.

I'm OK to remove the boilerplate if possible.

> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   tests/functional/qemu_test/tesseract.py | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/functional/qemu_test/tesseract.py b/tests/functional/qemu_test/tesseract.py
> index ede6c6501e2..1f955d32b76 100644
> --- a/tests/functional/qemu_test/tesseract.py
> +++ b/tests/functional/qemu_test/tesseract.py
> @@ -1,19 +1,24 @@
> -# ...
> +# SPDX-License-Identifier: GPL-2.0-or-later
>   #
>   # Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
>   #
>   # This work is licensed under the terms of the GNU GPL, version 2 or
>   # later. See the COPYING file in the top-level directory.
> +'''
> +Tesseract is an program for doing Optical Character Recognition (OCR),
> +which can be used in the tests to extract text from screenshots.
> +'''
>   
>   import logging
>   from subprocess import run
>   
>   
> -def tesseract_ocr(image_path, tesseract_args=''):
> +def tesseract_ocr(image_path):
> +    ''' Run the tesseract OCR to extract text from a screenshot '''
>       console_logger = logging.getLogger('console')
>       console_logger.debug(image_path)
>       proc = run(['tesseract', image_path, 'stdout'],
> -               capture_output=True, encoding='utf8')
> +               capture_output=True, encoding='utf8', check=False)
>       if proc.returncode:
>           return None
>       lines = []