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
This commit is contained in:
Marco Trevisan (Treviño) 2020-03-27 21:03:33 +01:00 committed by Marco Trevisan
parent c26588942a
commit e7ff4f705c

View file

@ -3,11 +3,10 @@
import sys import sys
try: try:
import gi import gi
gi.require_version('FPrint', '2.0')
from gi.repository import FPrint, GLib, Gio
import os import os
import sys
from gi.repository import GLib, Gio
import unittest import unittest
import socket import socket
import struct import struct
@ -20,6 +19,8 @@ except Exception as e:
print("Missing dependencies: %s" % str(e)) print("Missing dependencies: %s" % str(e))
sys.exit(77) sys.exit(77)
FPrint = None
# Re-run the test with the passed wrapper if set # Re-run the test with the passed wrapper if set
wrapper = os.getenv('LIBFPRINT_TEST_WRAPPER') wrapper = os.getenv('LIBFPRINT_TEST_WRAPPER')
if wrapper: if wrapper:
@ -101,12 +102,14 @@ class VirtualImage(unittest.TestCase):
del self.con del self.con
self.dev.close_sync() 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)) self.con.sendall(struct.pack('ii', -1, retry_error))
while iterate and ctx.pending(): while iterate and ctx.pending():
ctx.iteration(False) 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)) self.con.sendall(struct.pack('ii', -2, device_error))
while iterate and ctx.pending(): while iterate and ctx.pending():
ctx.iteration(False) ctx.iteration(False)
@ -346,5 +349,12 @@ class VirtualImage(unittest.TestCase):
assert(not self._verify_match) assert(not self._verify_match)
if __name__ == '__main__': 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 # avoid writing to stderr
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)) unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))