am-freescan/scripts/test_real_scan_flow.py

40 lines
2.3 KiB
Python
Raw Normal View History

"""Regression contract for the retained real-scanner workflow; no hardware access."""
import json
import unittest
from prepare_real_scan_task import flow
class RealScanFlowTest(unittest.TestCase):
def test_project_is_created_in_trak_mode_before_acquisition(self):
nodes=flow()['nodes']; actions=[n['properties']['action'] for n in nodes]
self.assertEqual(actions.count('SCANNER_CREATE_PROJECT'),1)
self.assertLess(actions.index('SCANNER_STOP'),actions.index('SCANNER_CREATE_PROJECT'))
self.assertLess(actions.index('SCANNER_CREATE_PROJECT'),actions.index('SCANNER_PREVIEW_START'))
self.assertLess(actions.index('SCANNER_CREATE_PROJECT'),actions.index('SCANNER_START'))
project=nodes[actions.index('SCANNER_CREATE_PROJECT')]
request=next(p['input'] for p in project['properties']['nodeParams'] if p['name']=='requestJson')
self.assertEqual(json.loads(request),{'mode':'trak'}) # Server assigns a fresh directory, including on retry.
def test_snapshot_is_requested_while_acquisition_can_still_produce_callbacks(self):
actions=[n['properties']['action'] for n in flow()['nodes']]
self.assertLess(actions.index('SCANNER_START'),actions.index('SLEEP'))
self.assertLess(actions.index('SLEEP'),actions.index('SCANNER_SNAPSHOT'))
stop=max(i for i,action in enumerate(actions) if action=='SCANNER_STOP')
self.assertLess(actions.index('SCANNER_SNAPSHOT'),stop)
self.assertLess(stop,actions.index('END'))
def test_controls_are_bound_and_connected_without_a_path_that_skips_stop(self):
graph=flow(); nodes=graph['nodes']; edges=graph['edges']
self.assertEqual([(e['sourceNodeId'],e['targetNodeId']) for e in edges],
[(a['id'],b['id']) for a,b in zip(nodes,nodes[1:])])
for node in nodes:
p=node['properties']
if p['action'].startswith('SCANNER_'):
self.assertEqual(p['executionTarget'],{'roleKey':'scanner','deviceSlotKey':'scanner'})
params={x['name']:x['input'] for x in p['nodeParams']}
self.assertGreater(params['timeoutMs'],0); self.assertIsInstance(json.loads(params['requestJson']),dict)
self.assertFalse(any(n['properties']['action'].startswith(('MOTOR_','SCANNER_CALIBRATION_')) for n in nodes))
if __name__=='__main__': unittest.main()