From e7ff4f705c544c5f3b083a88189fc4307333b0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 27 Mar 2020 21:03:33 +0100 Subject: [PATCH] tests: Import FPrint only during execution not when parsing The unittest_parser script would try to import FPrint gi module, but it would fail as per the fact that none is installed yet, so make sure that we don't load any FPrint module until we try to actually run the tests --- tests/virtual-image.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/virtual-image.py b/tests/virtual-image.py index b6cad95a..0df43e8d 100755 --- a/tests/virtual-image.py +++ b/tests/virtual-image.py @@ -3,11 +3,10 @@ import sys try: import gi - gi.require_version('FPrint', '2.0') - from gi.repository import FPrint, GLib, Gio - import os - import sys + + from gi.repository import GLib, Gio + import unittest import socket import struct @@ -20,6 +19,8 @@ except Exception as e: print("Missing dependencies: %s" % str(e)) sys.exit(77) +FPrint = None + # Re-run the test with the passed wrapper if set wrapper = os.getenv('LIBFPRINT_TEST_WRAPPER') if wrapper: @@ -101,12 +102,14 @@ class VirtualImage(unittest.TestCase): del self.con self.dev.close_sync() - def send_retry(self, retry_error=FPrint.DeviceRetry.TOO_SHORT, iterate=True): + def send_retry(self, retry_error=None, iterate=True): + retry_error = retry_error if retry_error else FPrint.DeviceRetry.TOO_SHORT self.con.sendall(struct.pack('ii', -1, retry_error)) while iterate and ctx.pending(): ctx.iteration(False) - def send_error(self, device_error=FPrint.DeviceError.GENERAL, iterate=True): + def send_error(self, device_error=None, iterate=True): + device_error = device_error if device_error else FPrint.DeviceError.GENERAL self.con.sendall(struct.pack('ii', -2, device_error)) while iterate and ctx.pending(): ctx.iteration(False) @@ -346,5 +349,12 @@ class VirtualImage(unittest.TestCase): assert(not self._verify_match) if __name__ == '__main__': + try: + gi.require_version('FPrint', '2.0') + from gi.repository import FPrint + except Exception as e: + print("Missing dependencies: %s" % str(e)) + sys.exit(77) + # avoid writing to stderr unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))