def setUp(self): """Create a Controller, TriggerGate and PoolSynchronization objects from dummy configurations """ unittest.TestCase.setUp(self) try: from mock import Mock except ImportError: self.skipTest("mock module is not available") pool = FakePool() dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01) self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl, dummyTriggerGateConf01) dummy_tg_ctrl.add_element(self.dummy_tg) pool.add_element(dummy_tg_ctrl) pool.add_element(self.dummy_tg) self.conf_ctrl = createControllerConfiguration(dummy_tg_ctrl, [self.dummy_tg]) self.ctrls = get_acq_ctrls([self.conf_ctrl]) # self.cfg = createPoolSynchronizationConfiguration((dummy_tg_ctrl,), # ((self.dummy_tg,),),) # Create mock and define its functions ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne', 'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne', 'PreSynchAll', 'PreSynchOne', 'SynchOne', 'SynchAll'] self.mock_tg_ctrl = Mock(spec=ctrl_methods) self.mock_tg_ctrl.StateOne.return_value = (State.Moving, 'triggering') dummy_tg_ctrl.ctrl = self.mock_tg_ctrl self.tgaction = PoolSynchronization(self.dummy_tg) self.tgaction.add_element(self.dummy_tg)
def setUp(self): """Create a Controller, TriggerGate and PoolSynchronization objects from dummy configurations """ unittest.TestCase.setUp(self) try: from mock import Mock except ImportError: self.skipTest("mock module is not available") pool = FakePool() dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01) self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl, dummyTriggerGateConf01) dummy_tg_ctrl.add_element(self.dummy_tg) pool.add_element(dummy_tg_ctrl) pool.add_element(self.dummy_tg) self.cfg = createPoolSynchronizationConfiguration( (dummy_tg_ctrl, ), ((self.dummy_tg, ), ), ) # Create mock and define its functions ctrl_methods = [ 'PreStartAll', 'StartAll', 'PreStartOne', 'StartOne', 'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne', 'PreSynchAll', 'PreSynchOne', 'SynchOne', 'SynchAll' ] self.mock_tg_ctrl = Mock(spec=ctrl_methods) self.mock_tg_ctrl.StateOne.return_value = (State.Moving, 'triggering') dummy_tg_ctrl.ctrl = self.mock_tg_ctrl self.tgaction = PoolSynchronization(self.dummy_tg) self.tgaction.add_element(self.dummy_tg)
def setUp(self): """Create a Controller, and Motor objects from dummy configurations """ unittest.TestCase.setUp(self) try: from mock import Mock except ImportError: self.skipTest("mock module is not available") pool = FakePool() dummy_mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01) self.dummy_mot = createPoolMotor(pool, dummy_mot_ctrl, dummyMotorConf01) self.dummy_mot2 = createPoolMotor(pool, dummy_mot_ctrl, dummyMotorConf02) dummy_mot_ctrl.add_element(self.dummy_mot) pool.add_element(dummy_mot_ctrl) pool.add_element(self.dummy_mot) pool.add_element(self.dummy_mot2) # {moveable: (position, dial_position, # do_backlash, backlash, instability_time=None)} self.items = {self.dummy_mot: (0, 0, False, 0), self.dummy_mot2: (0, 0, False, 0)} # Create mock and define its functions ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne', 'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne', 'PreReadAll', 'PreReadOne', 'ReadOne', 'ReadAll', 'PreStopAll', 'StopAll', 'PreStopOne', 'StopOne', 'PreAbortAll', 'AbortAll', 'PreAbortOne', 'AbortOne'] self.mock_mot_ctrl = Mock(spec=ctrl_methods) self.mock_mot_ctrl.StateOne.return_value = (State.Moving, 'moving') dummy_mot_ctrl.ctrl = self.mock_mot_ctrl self.motionaction = PoolMotion(self.dummy_mot) self.motionaction.add_element(self.dummy_mot) self.motionaction.add_element(self.dummy_mot2)
def setUp(self): """Setup: - Use resources for Controller, CounterTimer and MeasurementGroup features. - Create Controller, CounterTimer and MeasurementGroup. """ pool = FakePool() pc = createPoolController(pool, dummyPoolCTCtrlConf01) pct = createPoolCounterTimer(pool, pc, dummyCounterTimerConf01) pc.add_element(pct) pool.add_element(pc) pool.add_element(pct) self.pmg = createPoolMeasurementGroup(pool, dummyMeasurementGroupConf01) self._pct = pct # keep a reference to use it in test_acquisition
def createElements(self, ctrl_klass, ctrl_lib, ctrl_props): # create controller and element ctrl_conf = createCtrlConf(self.pool, 'tgctrl01', ctrl_klass, ctrl_lib, ctrl_props) elem_conf = createElemConf(self.pool, 1, 'tg01') self.tg_ctrl = createPoolController(self.pool, ctrl_conf) self.tg_elem = createPoolTriggerGate(self.pool, self.tg_ctrl, elem_conf) # add controller and elements to containers self.tg_ctrl.add_element(self.tg_elem) self.pool.add_element(self.tg_ctrl) self.pool.add_element(self.tg_elem) # create Synchronization action and its configuration self.conf_ctrl = createControllerConfiguration(self.tg_ctrl, [self.tg_elem]) self.ctrls = get_acq_ctrls([self.conf_ctrl]) self.tgaction = PoolSynchronization(self.tg_elem) self.tgaction.add_element(self.tg_elem)
def setUp(self): """Create a Controller, TriggerGate and PoolSynchronization objects from dummy configurations """ unittest.TestCase.setUp(self) pool = FakePool() dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01) self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl, dummyTriggerGateConf01) # marrying the element with the controller dummy_tg_ctrl.add_element(self.dummy_tg) self.ctrl_conf = createControllerConfiguration(dummy_tg_ctrl, [self.dummy_tg]) # marrying the element with the action self.tg_action = PoolSynchronization(self.dummy_tg) self.tg_action.add_element(self.dummy_tg)
def test_state(monkeypatch, mock_StateOne): """Test variants of StateOne return value: - state - state, status """ pool = FakePool() # when SEP19 gets implemented it should be possible to mock directly # the imported class DummyCounterTimerController = pool.ctrl_manager.getControllerClass( "DummyCounterTimerController") monkeypatch.setattr(DummyCounterTimerController, "StateOne", mock_StateOne) ct_ctrl = createPoolController(pool, dummyPoolCTCtrlConf01) ct = createPoolCounterTimer(pool, ct_ctrl, dummyCounterTimerConf01) ct_ctrl.add_element(ct) pool.add_element(ct_ctrl) pool.add_element(ct) assert ct.state == State.On assert type(ct.status) == str
def test_state(monkeypatch, mock_StateOne): """Test variants of StateOne return value: - state - state, status - state, status, limit_switches """ pool = FakePool() # when SEP19 gets implemented it should be possible to mock directly # the imported class DummyMotorController = pool.ctrl_manager.getControllerClass( "DummyMotorController") monkeypatch.setattr(DummyMotorController, "StateOne", mock_StateOne) mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01) mot = createPoolMotor(pool, mot_ctrl, dummyMotorConf01) mot_ctrl.add_element(mot) pool.add_element(mot_ctrl) pool.add_element(mot) assert mot.state == State.On assert type(mot.status) == str assert mot.limit_switches.value == (False, ) * 3
def createController(self, name, klass, lib, props={}): c_cfg = createCtrlConf(self.pool, name, klass, lib, props) ctrl_obj = createPoolController(self.pool, c_cfg) self.ctrls[name] = ctrl_obj self.pool.add_element(ctrl_obj) return ctrl_obj
def setUp(self): """Create a Controller and a CounterTimer element""" pool = FakePool() pc = createPoolController(pool, dummyPoolCTCtrlConf01) self.pct = createPoolCounterTimer(pool, pc, dummyCounterTimerConf01)
def setUp(self): """Instantiate a fake Pool and create a Controller""" pool = FakePool() self.pc = createPoolController(pool, dummyPoolCTCtrlConf01)