Skip to content

Commit

Permalink
tests/virtual-device: Add function that figures out the command from …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
3v1n0 committed Jan 25, 2021
1 parent 81e53c4 commit dfb2722
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions tests/virtual-device.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ def send_finger_report(self, has_finger, iterate=True):
while not (self.dev.get_finger_status() & expected):
ctx.iteration(True)

def send_error(self, error):
self.assertIsInstance(error, FPrint.DeviceError)
self.send_command('ERROR', int(error))

def send_retry(self, retry):
self.assertIsInstance(retry, FPrint.DeviceRetry)
self.send_command('RETRY', int(retry))

def send_auto(self, obj):
if isinstance(obj, FPrint.DeviceError):
self.send_error(obj)
elif isinstance(obj, FPrint.DeviceRetry):
self.send_retry(obj)
elif isinstance(obj, FPrint.FingerStatusFlags):
self.send_finger_report(obj & FPrint.FingerStatusFlags.PRESENT, iterate=False)
elif isinstance(obj, FPrint.ScanType):
self.send_command('SET_SCAN_TYPE', obj.value_nick)
else:
raise Exception('No known type found for {}'.format(obj))

def enroll_print(self, nick, finger, username='testuser'):
self._enrolled = None

Expand Down Expand Up @@ -172,10 +192,8 @@ def check_verify(self, p, scan_nick, match):

if isinstance(scan_nick, str):
self.send_command('SCAN', scan_nick)
elif isinstance(scan_nick, FPrint.DeviceError):
self.send_command('ERROR', int(scan_nick))
elif isinstance(scan_nick, FPrint.DeviceRetry):
self.send_command('RETRY', int(scan_nick))
else:
self.send_auto(scan_nick)

def verify_cb(dev, res):
try:
Expand Down Expand Up @@ -302,7 +320,7 @@ def on_scan_type_changed(dev, spec):

for scan_type in [FPrint.ScanType.PRESS, FPrint.ScanType.SWIPE]:
notified_spec = None
self.send_command('SET_SCAN_TYPE', scan_type.value_nick)
self.send_auto(scan_type)
self.assertEqual(self.dev.get_scan_type(), scan_type)
self.assertEqual(notified_spec.name, 'scan-type')

Expand Down

0 comments on commit dfb2722

Please sign in to comment.