aboutsummaryrefslogtreecommitdiff
path: root/tests/acceptance/tesseract_utils.py
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-02-08 20:22:54 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-02-08 20:22:54 +0000
commit34b7d4193e450d0799be4ca58323d0dcbb0075cc (patch)
tree3acb4559bac4dcc7027af64cbacb15c840d73287 /tests/acceptance/tesseract_utils.py
parent2436651b26584c8ebe91db5df67ee054509a0949 (diff)
parent86b7cb6660bfec139f293c246572f77b53389699 (diff)
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/integration-testing-20210208' into staging
Integration testing patches Tests added: - Armbian 20.08 on Orange Pi PC (Philippe) - MPC8544ds machine (Thomas) - Virtex-ml507 ppc machine (Thomas) - Re-enable the microblaze test (Thomas) Various fixes and documentation improvements from Cleber. # gpg: Signature made Mon 08 Feb 2021 20:19:12 GMT # gpg: using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full] # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * remotes/philmd-gitlab/tags/integration-testing-20210208: Acceptance Tests: remove unnecessary tag from documentation example Acceptance tests: clarify ssh connection failure reason tests/acceptance/virtiofs_submounts: required space between IP and port tests/acceptance/virtiofs_submounts: standardize port as integer tests/acceptance/virtiofs_submounts: use a virtio-net device instead tests/acceptance/virtiofs_submounts: do not ask for ssh key password tests/acceptance/virtiofs_submounts: use workdir property tests/acceptance/boot_linux: rename misleading cloudinit method tests/acceptance/boot_linux: fix typo on cloudinit error message tests/acceptance: Re-enable the microblaze test tests/acceptance: Add a test for the virtex-ml507 ppc machine tests/acceptance: Test the mpc8544ds machine tests/acceptance: Move the pseries test to a separate file tests/acceptance: Test U-Boot/Linux from Armbian 20.08 on Orange Pi PC tests/acceptance: Extract do_test_arm_orangepi_armbian_uboot() method tests/acceptance: Introduce tesseract_ocr() helper tests/acceptance: Extract tesseract_available() helper in new namespace Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/acceptance/tesseract_utils.py')
-rw-r--r--tests/acceptance/tesseract_utils.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/acceptance/tesseract_utils.py b/tests/acceptance/tesseract_utils.py
new file mode 100644
index 0000000000..72cd9ab798
--- /dev/null
+++ b/tests/acceptance/tesseract_utils.py
@@ -0,0 +1,46 @@
+# ...
+#
+# 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.
+
+import re
+import logging
+
+from avocado.utils import process
+from avocado.utils.path import find_command, CmdNotFoundError
+
+def tesseract_available(expected_version):
+ try:
+ find_command('tesseract')
+ except CmdNotFoundError:
+ return False
+ res = process.run('tesseract --version')
+ try:
+ version = res.stdout_text.split()[1]
+ except IndexError:
+ version = res.stderr_text.split()[1]
+ return int(version.split('.')[0]) == expected_version
+
+ match = re.match(r'tesseract\s(\d)', res)
+ if match is None:
+ return False
+ # now this is guaranteed to be a digit
+ return int(match.groups()[0]) == expected_version
+
+
+def tesseract_ocr(image_path, tesseract_args='', tesseract_version=3):
+ console_logger = logging.getLogger('tesseract')
+ console_logger.debug(image_path)
+ if tesseract_version == 4:
+ tesseract_args += ' --oem 1'
+ proc = process.run("tesseract {} {} stdout".format(tesseract_args,
+ image_path))
+ lines = []
+ for line in proc.stdout_text.split('\n'):
+ sline = line.strip()
+ if len(sline):
+ console_logger.debug(sline)
+ lines += [sline]
+ return lines