async def test_hw_manager(loop): # When built without an input it should build its own adapter mgr = HardwareManager(None) adapter = mgr.hardware # When "disconnecting" from its own simulator, the adapter should # be stopped and a new one created new = mgr.reset_hw() assert new is not adapter # When deleted, the self-created adapter should be stopped del mgr # When built with a hardware API input it should wrap it with a new # synchronous adapter and not build its own API sim = await API.build_hardware_simulator(loop=loop) mgr = HardwareManager(sim) assert isinstance(mgr.hardware, adapters.SynchronousAdapter) passed = mgr.hardware # When disconnecting from a real external adapter, it should create # its own simulator and should new = mgr.reset_hw() assert new is not passed thread_manager = ThreadManager(API.build_hardware_simulator) sa = thread_manager.sync # When connecting to an adapter it shouldn’t rewrap it assert mgr.set_hw(sa) is sa del mgr thread_manager.clean_up()
async def test_synch_adapter(): thread_manager = ThreadManager(API.build_hardware_simulator) synch = thread_manager.sync synch.cache_instruments({Mount.LEFT: 'p10_single'}) assert synch.attached_instruments[Mount.LEFT]['name']\ .startswith('p10_single') thread_manager.clean_up()
def sync_hardware(request, loop, virtual_smoothie_env): thread_manager = ThreadManager(API.build_hardware_controller) hardware = thread_manager.sync try: yield hardware finally: hardware.reset() hardware.set_config(config.robot_configs.load()) thread_manager.clean_up()
async def hardware(request, loop, virtual_smoothie_env): hw_sim = ThreadManager(API.build_hardware_simulator) old_config = config.robot_configs.load() try: yield hw_sim finally: config.robot_configs.clear() hw_sim.set_config(old_config) hw_sim.clean_up()