def test_tggeneration(self): """Verify trigger element states before and after action_loop.""" from mock import call args = () kwargs = {'config': self.cfg} # starting action self.tgaction.start_action(*args, **kwargs) # verifying that the action correctly started the involved controller self.mock_tg_ctrl.assert_has_calls([ call.PreStartAll(), (call.PreStartOne(1, )), (call.StartOne(1, )), (call.StartAll()) ]) # verifying that the elements involved in action changed its state element_state = self.dummy_tg.get_state() msg = ("State after start_action is '%s'. (Expected: '%s')" % (State.get(element_state), "Moving")) self.assertEqual(element_state, State.Moving, msg) # starting timer (1 s) which will change the controller state threading.Timer(1, self.stopGeneration).start() # entering action loop self.tgaction.action_loop() # verifying that the action checked the controller states self.mock_tg_ctrl.assert_has_calls([ call.PreStateAll(), call.PreStateOne(1, ), call.StateAll(), call.StateOne(1, ) ]) # verifying that the elements involved in action changed its state element_state = self.dummy_tg.get_state() msg = ("State after action_loop shall be different than Moving") self.assertNotEqual(element_state, State.Moving, msg)
def test_tggeneration(self): """Verify trigger element states before and after action_loop.""" from mock import call, MagicMock # starting action synchronization = MagicMock() self.tgaction.start_action(self.ctrls, synchronization) # verifying that the action correctly started the involved controller self.mock_tg_ctrl.assert_has_calls([call.PreStartAll(), (call.PreStartOne(1,)), (call.StartOne(1,)), (call.StartAll())]) # verifying that the elements involved in action changed its state element_state = self.dummy_tg.get_state() msg = ("State after start_action is '%s'. (Expected: '%s')" % (State.get(element_state), "Moving")) self.assertEqual(element_state, State.Moving, msg) # starting timer (1 s) which will change the controller state threading.Timer(1, self.stopGeneration).start() # entering action loop self.tgaction.action_loop() # verifying that the action checked the controller states self.mock_tg_ctrl.assert_has_calls([call.PreStateAll(), call.PreStateOne(1,), call.StateAll(), call.StateOne(1,)]) # verifying that the elements involved in action changed its state element_state = self.dummy_tg.get_state() msg = ("State after action_loop shall be different than Moving") self.assertNotEqual(element_state, State.Moving, msg)
def abort_tggeneration(self, ctrl_lib, ctrl_klass, ctrl_props, synchronization, abort_time): """Helper method to verify trigger element states before and after trigger/gate generation when aborting the trigger generation. :param ctrl_lib: controller library used for the test :type ctrl_lib: :obj:`str` :param ctrl_klass: controller class used for the test :type ctrl_klass: :obj:`str` :param offset: temporal offset before beginning the trigger generation :type offset: float :param active_interval: signal at which triggers will be generated :type active_interval: float :param passive_interval: temporal passive period between two active periods :type passive_interval: float :param repetitions: number of generated triggers :type repetitions: int :param abort_time: wait this time before stopping the trigger generation :type abort_time: float """ # create controller and trigger element self.createElements(ctrl_klass, ctrl_lib, ctrl_props) # create start_action arguments args = (self.ctrls, synchronization) kwargs = {} # starting action self.tgaction.start_action(*args, **kwargs) # verifying that the elements involved in action changed its state element_state = self.tg_elem.get_state() msg = ("State after start_action is '%s'. (Expected: '%s')" % (State.get(element_state), "Moving")) self.assertEqual(element_state, State.Moving, msg) # starting timer (abort_time) stop the trigger generation threading.Timer(abort_time, self.stopGeneration).start() # entering action loop self.tgaction.action_loop() # verifying that the elements involved in action changed its state element_state = self.tg_elem.get_state() msg = ("State after action_loop shall be different than Moving") self.assertNotEqual(element_state, State.Moving, msg)