def test_invalid_plug(self): with self.assertRaises(plugs.InvalidPlugError): self.plug_manager.initialize_plugs({object}) with self.assertRaises(plugs.InvalidPlugError): plugs.plug(adder_plug=object) with self.assertRaises(plugs.InvalidPlugError): self.plug_manager.initialize_plugs({ type('BadPlug', (plugs.BasePlug,), {'logger': None})}) with self.assertRaises(plugs.InvalidPlugError): self.plug_manager.wait_for_plug_update('invalid', {}, 0)
def test_invalid_plug(self): with self.assertRaises(plugs.InvalidPlugError): self.plug_manager.initialize_plugs({object}) with self.assertRaises(plugs.InvalidPlugError): plugs.plug(adder_plug=object) with self.assertRaises(plugs.InvalidPlugError): self.plug_manager.initialize_plugs({ type('BadPlug', (plugs.BasePlug,), {'logger': None})}) with self.assertRaises(plugs.InvalidPlugError): class BadPlugInit(plugs.BasePlug): def __init__(self): self.logger = None self.plug_manager.initialize_plugs({BadPlugInit}) with self.assertRaises(plugs.InvalidPlugError): self.plug_manager.wait_for_plug_update('invalid', {}, 0)
def Wrapper(phase_func): @functools.wraps(phase_func) def MonitoredPhaseFunc(phase_data, *args, **kwargs): # Start monitor thread, it will call monitor.func(phase_data) periodically monitor_thread = _MonitorThread( measurement_name, monitor, phase_data, poll_interval_ms) monitor_thread.start() try: return phase_func(phase_data, *args, **kwargs) finally: monitor_thread.Kill() phase = openhtf.PhaseInfo.WrapOrCopy(phase_func) # Re-key this dict so we don't have to worry about collisions with # plug.plug() decorators on the phase function. Since we aren't # updating kwargs here, we don't have to worry about collisions with # kwarg names. monitor_plugs = {('_' * idx) + measurement_name + '_monitor': plug.cls for idx, plug in enumerate(monitor.plugs, start=1)} plug_decorator = plugs.plug(update_kwargs=False, **monitor_plugs) measures_decorator = measurements.measures( measurements.Measurement(measurement_name).WithUnits( units).WithDimensions(uom.UOM['MILLISECOND'])) phase_func, phase.func = phase.func, MonitoredPhaseFunc return plug_decorator(measures_decorator(phase))