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, 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, 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 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