def test_capture_prevents_close(self): cancel = Gio.Cancellable() def cancelled_cb(dev, res, obj): print("Capture operation finished") with self.assertRaises(GLib.GError) as cm: dev.capture_finish(res) assert cm.exception.matches(Gio.io_error_quark(), Gio.IOErrorEnum.CANCELLED) print("Capture cancelled as expected") obj._cancelled = True self._cancelled = False self.dev.capture(True, cancel, cancelled_cb, self) with self.assertRaises(GLib.GError) as cm: self.dev.close_sync() assert cm.exception.matches(FPrint.device_error_quark(), FPrint.DeviceError.BUSY) cancel.cancel() while not self._cancelled: ctx.iteration(True)
def setUpClass(cls): cls.tmpdir = tempfile.mkdtemp(prefix='libfprint-') cls.sockaddr = os.path.join(cls.tmpdir, 'virtual-image.socket') os.environ['FP_VIRTUAL_IMAGE'] = cls.sockaddr cls.ctx = FPrint.Context() cls.dev = None for dev in cls.ctx.get_devices(): # We might have a USB device in the test system that needs skipping if dev.get_driver() == 'virtual_image': cls.dev = dev break assert cls.dev is not None, "You need to compile with virtual_image for testing" cls.prints = {} for f in glob.glob(os.path.join(imgdir, '*.png')): n = os.path.basename(f)[:-4] cls.prints[n] = load_image(f)
#!/usr/bin/python3 import gi gi.require_version('FPrint', '2.0') from gi.repository import FPrint, GLib ctx = GLib.main_context_default() c = FPrint.Context() c.enumerate() devices = c.get_devices() d = devices[0] assert d.get_driver() == "synaptics" d.open_sync() template = FPrint.Print.new(d) def enroll_progress(*args): print('enroll progress: ' + str(args)) # List, enroll, list, verify, delete, list print("enrolling") p = d.enroll_sync(template, None, enroll_progress, None) print("enroll done") print("listing") stored = d.list_prints_sync() print("listing done")