示例#1
0
class PoolDummyTriggerGateTestCase(unittest.TestCase):
    """Parameterizable integration test of the PoolSynchronization action and
    the DummTriggerGateController.

    Using insertTest decorator, one can add tests of a particular trigger/gate
    characteristic.
    """

    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 generation(self, synchronization):
        """Verify that the created PoolTGAction start_action starts correctly
        the involved controller."""
        args = ([self.ctrl_conf], synchronization)
        self.tg_action.start_action(*args)
        self.tg_action.action_loop()
        # TODO: add asserts applicable to a dummy controller e.g. listen to
        # state changes and verify if the change ON->MOVING-ON was emitted

    def tearDown(self):
        unittest.TestCase.tearDown(self)
示例#2
0
class SynchronizationTestCase(object):
    """Base class for integration tests of PoolSynchronization class and any
    PoolTriggerGateController. Test is parameterized using trigger parameters.

    .. seealso:: :meth:`taurus.test.base.insertTest`"""
    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.tg_cfg = createPoolSynchronizationConfiguration(
            (self.tg_ctrl, ),
            ((self.tg_elem, ), ),
        )
        self.tgaction = PoolSynchronization(self.tg_elem)
        self.tgaction.add_element(self.tg_elem)

    def setUp(self):
        """Create a FakePool object.
        """
        self.pool = FakePool()

    def tggeneration(self, ctrl_lib, ctrl_klass, ctrl_props, synchronization):
        """Helper method to verify trigger element states before and after
        trigger/gate 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
        """

        # create controller and trigger element
        self.createElements(ctrl_klass, ctrl_lib, ctrl_props)

        # create start_action arguments
        args = ()
        kwargs = {'config': self.tg_cfg, 'synchronization': synchronization}
        # 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)
        # 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)

    def stopGeneration(self):
        """Method used to change the controller (mock) state"""
        self.tgaction.stop_action()

    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 = ()
        kwargs = {'config': self.tg_cfg, 'synchronization': synchronization}
        # 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)

    def tearDown(self):
        self.tgaction = None
        self.tg_ctrl = None
        self.tg_cfg = None
        self.tg_elem = None
class SynchronizationTestCase(object):
    """Base class for integration tests of PoolSynchronization class and any
    PoolTriggerGateController. Test is parameterized using trigger parameters.

    .. seealso:: :meth:`taurus.test.base.insertTest`"""

    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 FakePool object.
        """
        self.pool = FakePool()

    def tggeneration(self, ctrl_lib, ctrl_klass, ctrl_props,
                     synchronization):
        """Helper method to verify trigger element states before and after
        trigger/gate 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
        """

        # 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)
        # 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)

    def stopGeneration(self):
        """Method used to change the controller (mock) state"""
        self.tgaction.stop_action()

    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)

    def tearDown(self):
        self.tgaction = None
        self.tg_ctrl = None
        self.tg_cfg = None
        self.tg_elem = None
示例#4
0
class PoolTriggerGateTestCase(unittest.TestCase):
    """Unittest of PoolSynchronization class"""
    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 stopGeneration(self):
        """Method used to change the controller (mock) state"""
        self.mock_tg_ctrl.StateOne.return_value = (State.On, 'On')

    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 tearDown(self):
        self.tgaction = None
        self.mock_tg_ctrl = None
        self.cfg = None
        self.dummy_tg = None
        unittest.TestCase.tearDown(self)
class PoolTriggerGateTestCase(unittest.TestCase):
    """Unittest of PoolSynchronization class"""

    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 stopGeneration(self):
        """Method used to change the controller (mock) state"""
        self.mock_tg_ctrl.StateOne.return_value = (State.On, 'On')

    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 tearDown(self):
        self.tgaction = None
        self.mock_tg_ctrl = None
        self.cfg = None
        self.dummy_tg = None
        unittest.TestCase.tearDown(self)